patterns on showing an empty textfield in Android

455 views Asked by At

Well I am developing a simple Tip Calculator app as a part of a course and I was faced with the problem that if the user enters an empty text field, how should the error be shown to the user.

I thought of 3 ways:

  1. Show a Dialog stating Bill Amount not specified [Though this is really very lame.]
  2. To show a message in red stating "Bill Amount not specified" and highlighting the text field [Something similar to what it is done on the Web when you do not say enter a username on Gmail].
  3. Use the Animation class to kinda vibrate the text-field in order to show that its not populated.

I was wondering if there are some patterns or good practices which are followed in order to display an error message related to a required field being empty.

Thanks in advance

2

There are 2 answers

0
Dan On BEST ANSWER

I've found using Toasts and optionally slight style changes notifies users without being too intrusive. I cannot stand JavaScript popup boxes on websites.

Toast toast = Toast.makeText(this, "Bill amount not specified", Toast.LENGTH_SHORT);
toast.show();

Then animate your box or maybe add/change some red text to guide the user to the correct input box. This way notifies the user without requiring any additional input beyond fixing their mistake (like hitting "OK" on a dialog, etc)

4
Ben Williams On

I'd put up an AlertDialog with a "required field blank" message and then, on dismissal of that, set the user input focus to the field in question. (In HTML forms, it's pretty standard to turn the label red, so you could do that too; maybe use a key listener to turn the label back to its original colour when text is entered?)

ETA: or, have a textview with the "required field!" message in above the field but with visibility set to gone by default; then you can just change it to visible/not as needed, which will be a clear visual clue to the user without the annoyance of having to dismiss a dialog.

I'd find the animation thing really annoying. Basically, go with option 2.