how to toast a message if editText is empty by clicking button?

前端 未结 5 1045
暗喜
暗喜 2021-01-24 09:19

i have 2 edit Text in my application, 1 button to add the input numbers in the edit Text and 1 text view to display the result. I would like to put a toast message if my edit te

5条回答
  •  旧时难觅i
    2021-01-24 09:41

    when user clicks button check:

    if (editText1.getText().toString().trim().length() <= 0) {
        Toast.makeText(MainActivity.this, "It's empty", Toast.LENGTH_SHORT).show();
    }
    

    trim it to avoid blank spaces.

提交回复
热议问题