Jurza Jurza - 1 year ago 55
Android Question

Android show newest toast

I'm working on my first Android app and I have a situation that really annoys me.

Lets say that user has to enter some information in few Edit Text fields and can't proceed if there is at least one empty field.

If user clicks a button to proceed and there is at least one empty field, a certain Toast is displayed.

The problem is, if user clicks that button like 10 times, and then enters those missing information and proceeds, those Toast messages keep showing in the new Activity along with Toast for successful registration.

Is there a way to interrupt a currently displayed Toast and display newest or something similar that will stop this kind of behaviour from happening?

edit: I have accepted @Vucko's answer because it suits better for my problem. @Augusto Carmo wrote the answer that indeed works, but I prefer Vucko's answer, it is just more elegant.

Answer Source

The more elegant and common way to do this would be to use:

editText.setError("Your error message");

This will disappear itself once you write something in your editText or you can manually remove it by calling setError(null);.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download