Check if an Edit Text that only accepts number is not empty and the number is equal or less than 100

前端 未结 5 1328
清歌不尽
清歌不尽 2020-12-20 07:57

I\'m building an application for receiving grades and I want to make sure that the Edit Texts are not empty and the values are less or equal to 100 I wrote this line but it

5条回答
  •  感情败类
    2020-12-20 08:33

    In your xml where you have declared edittext make sure that you put the following attribute in edittext element

    android:inputType="number"
    

    And change above code to this :

     if(editText.getText().toString().trim().isEmpty() || Integer.parseInt(editText.gettext().toString()) > 100 )
        {
        //Error message for example
        } 
    

    you first need to check if text is not empty

提交回复
热议问题