Validating TextView in Android
<p>I am making a reminder app in which the user needs to set date and time from date and time pickers. So I did the following:</p>

<pre><code>private TextView mDateDisplay;
private TextView mTimeDisplay;
...

// Set reminder button
setButton = (Button) findViewById(R.id.set_reminder_button);
setButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
    if (!validate()) {
        onSetDateTimeFailed();
        return;
       }
       // creating new product in background thread
        db.addReminder(id, mEditMessageText.getText().toString(), mDateDisplay.getText().toString(), mTimeDisplay.getText().toString());
        finish();
    }
});
...

//    Validation
public boolean validate() {
    boolean valid = true;

    String date = mDateDisplay.getText().toString();
    String time = mTimeDisplay.getText().toString();

    if (date.isEmpty() ) {
        mDateDisplay.setError("Set date");
        valid = false;
    } else {
        mDateDisplay.setError(null);
    }

    if (time.isEmpty()) {
        mTimeDisplay.setError("Set time");
        valid = false;
    } else {
        mTimeDisplay.setError(null);
    }

    return valid;
}

public void onSetDateTimeFailed() {
    Toast.makeText(getBaseContext(), "Setting date and time failed", Toast.LENGTH_LONG).show();

    setButton.setEnabled(true);
}
</code></pre>

<p>I get is the error symbols on the textviews (!), but the only toast message I get is the <em>"Setting date and time failed"</em> and not the <em>"Set date"</em> or <em>"Set time"</em>.</p>

<p>The other thing I wanted to do is add a reminder message to date and time:</p>

<pre><code>private EditText mEditMessageText;
...
//    Validation
public boolean validate() {
    boolean valid = true;

    String message = mEditMessageText.getText().toString();

    if (message.isEmpty() || time.length() &lt; 1 || time.length() &gt; 140) {
        mEditMessageText.setError("Enter between 1 and 140 characters");
        valid = false;
    } else {
        mEditMessageText.setError(null);
    }
</code></pre>

<p>But now I also get the <em>"Enter between 1 and 140 characters"</em> message when there is error in any validated field. For example, if I entered the needed number of letters in editText filed and did not select date or time I get this error message <em>"Enter between 1 and 140 characters"</em> and the error symbol (!) in editText as well.</p>