Search code examples
androidui-patterns

patterns on showing an empty textfield in Android


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


Solution

  • 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)