How to make the EditText text field mandatory? In order to press the message sending button, the application did not send a blank message, but checked for information in the text fields and if the field was empty, the button ignored pressing.

  • Maybe you mean EditText ? - katso
  • Yes, EditText . It was sealed up .. - BredBear

1 answer 1

If there is no text in the widget (including only spaces) - block click on the widget, if there is text - unlock:

  textView.setClickable(!(textView.getText().toString().trim().equals(""))); 

or

  int l = textView.getText().toString().trim().length(); textView.setClickable(l == 0 ? false: true); 

Call whenever it is necessary to check the content in a widget for its presence or absence and, accordingly, to allow a click on the widget to be processed or not.

Suitable for any widget that works out clicks and may contain text. In this case, using the TextView as an example.

  • Thank you This is what I was looking for! - BredBear
  • Is it possible to make a form with an e-mail address that will check its existence and the correctness of writing an e-mail address? - BredBear
  • @BredBear Validation of validity of input is of course possible, including for compliance with the form of email, only data validation is another matter and a different solution. Checking the existence of the mail is possible only by feedback. That is, you send a letter to this address, and the user clicks on a special link there or enters the received code, as is done with most registrations on websites - and this is the third separate question that goes beyond the first two. - pavlofff
  • Thank you for informing. - BredBear