I'm working on my first Android application 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.
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);.
Have a single Toast object, and when you want to show another toast message, you cancel the last one and show the new one. Example:
Toast toast = new Toast();
toast.makeText(CONTEXT_HERE, MESSAGE_HERE, TIME_HERE).show();
// displaying another
toast.cancel();
toast.makeText(CONTEXT_HERE, ANOTHER_MESSAGE_HERE, TIME_HERE).show();
Related
Expanding the functionality of an under development app, I need to show to the user a progress notification dialog. Problem is, I cannot get it done right. Furthermore, I cannot dismiss this notifier properly. Have tried with a clock and a variable set to e.g. "5000ms" and then to "0", without any lack.
What I need to achieve is the following functionality:
a. Check if the tag "storeparsedData" is in a TinyDB, populated with the fetched JSON data. I have this done, following #Taifun advice in my relative question.
b. If the tag is not there (empty list), do a getWeb.gotText block to get the JSON data (this is done with procedure "getWebData". This functions right, but takes a while about 1'35'' or more, so need to show something to the user.
c. While fetching JSON data form web, need to show a "ShowProgressDialog" notifier to the user, so I can cope with the smartphone being seemingly freeze.
d. If the tag "storeparseData" is populated with fetched JSON data, dismiss the notifier.
Have tried the following coding, without relevant success:
Can someone help me out, to achieve this functionality in this app? A blocks code or something to follow and learn, will be awesome.
Thank you all in advance for your answers.
[Edit1]
After #Taifun suggestions, the functionality in question seems to be working, but there is a problem."ShowProgressDialog" block never fires, neither on device or companion. Also where should block "DismissProgressDialog" be attached to disable notifier upon JSON data received?
Here is the reviewed blocks code, for checking stored tags in TinyDB. "ShowProgressDialog" never fires as it should. Are there any suggestion for this issue?
Here is the blocks code for the getWeb function to get the JSON data:
Please advise, with a block code if applicable.Thank you all.
Your progressNotifier.AfterChoosing event never will fire, because that event only fires after choosing something from a Notifier.ShowChooseDialog block, but not for Notifier.ShowMessageDialog blocks. Therefore use a Notifier.ShowChooseDialog block instead and set the second button in that block to empty string.
Your while loop will freeeze your app, as you already realized... You do not need the Clock.Timer event at all to check if your data is there.
Just do it like this: after having received your data in the Web.GotText event and having stored the data in TinyDB, then dismiss the progress dialog and display the message "Database is ready".
Update: Instead of storing your list n times inside the for each in list loop, you should store it only once after the for each in list loop is finished... Same for the DismissProgressDialog and ShowAlert block...
What is the purpose of that join block? You might want to remove it...
Once I have completed the form, I cannot see the the form's output in the ResultsLabel I created. Attached is a screenshot below, does it look OK?
All help appreciated!
Regarding your statement "I cannot see the form's output in the label", is it possible that it's hidden behind the keyboard? Press the 'Done' button to hide the keyboard when you're done typing.
Regarding your question "does it look OK":
Your first StoreValue event is saving the value as the tag, which probably isn't great practice but can work
However, your second StoreValue overwrites the first one, and the third StoreValue overwrites the second one because you're using the same tag for all three.
If you want to save the two thumbpositions for that particular name you should do this:
TinyDB.StoreValue
tag = {name.text}
value = {make a list
{cashrequired.thumbposition}
{period.thumbposition}
I need a Confirm dialog that returns the boolean value in order to remind the user about the missing series of values in the form that are required based on the settings but not mandatory.
I did lot of research but none of the tell me how to active this.
For example: In a form lets say the user forgot to enter City, State and Zip. I need to throw an reminder asking the user "Did you intentionally not enter the City?" with "Yes" and "No" buttons. If the user answers "Yes" then throw the reminder for State else set the focus to City, so that user can enter the city. And so on....
Any help would be greatly appreciated.
Thanks,
Vincy
First, what you are proposing is not a particularly friendly UX. Use color coding or something to indicate fields that you think should be filled in but are not, rather than forcing the user to have to keep tapping on dialogs to do what the user wants to do.
All that being said, use AlertDialog (perhaps via AlertDialog.Builder) and set up DialogInterface.OnClickListener objects for the buttons. Depending upon the button choice, you either set the focus (via requestFocus(), called on the widget needing focus) or continue with your processing.
Quick question: Is there a way to display a toast message that doesn't fade away until I call cancel() on it?
I have tried setting the duration to something like 9999 but that doesn't work.
Is there a way to display a toast message that doesn't fade away until I call cancel() on it?
No, not directly from the SDK, but you can "tweak" your Toast to make it live longer by calling show() on it as many times you wish using threads. See this article for more information.
A Toast that doesn't go away until you cancel it is called a Dialog (or AlertDialog). The integer you pass to Toast.setDuration() is a flag - not a value - it will only recognize the values Toast.LENGTH_SHORT and Toast.LENGTH_LONG.
The Toast calss description says:
"A toast is a view containing a quick little message for the user. The
toast class helps you create and show those..."
"...The idea is to be as unobtrusive as possible, while still showing the
user the information you want them to see. Two examples are the volume
control, and the brief message saying that your settings have been
saved..."
As for the duration parameter it should be one of LENGTH_LONG or LENGTH_SHORT - 1 or 0 respectively.
Use a dialogue that looks like a Toast if you really have to, but I don't recommend doing this because this wont be what a user expects from a Toast.
Toast Message works with time.there is no way to control it with the cancel.You have to use Dialog for the kind of purpose
The official doc says (http://developer.android.com/reference/android/widget/Toast.html#makeText(android.content.Context, int, int) ):
public static Toast makeText (Context context, int resId, int duration)
Since: API Level 1
Make a standard toast that just contains a text view with the text from a resource.
Parameters
context The context to use. Usually your Application or Activity object.
resId The resource id of the string resource to use. Can be formatted text.
duration How long to display the message. Either LENGTH_SHORT or LENGTH_LONG
Throws Resources.NotFoundException if the resource can't be found.
This means there is no direct way to do that. You will have to build your custom code for this. As Toasts exacly overlap each other you can call the same Toast every second with a thread as an example, and use a cancel() custom method to terminate that thread.
I know this post is old but for others that come across it you are more than welcome to use a little library I put together called SuperToasts.
You can find the library here.
There is an indeterminate option for Toasts that are added to an Activity namely the SuperActivityToast. I purposely did not add this feature to standard SuperToasts, a class that mimics standard Toasts, because the SuperToast can linger until your application is killed as it is added to the WindowManager and not an Activity. SuperActivityToasts are added to the Activity's content and will be destroyed along with your Activity hence the ability to make them indeterminate.
I am new to Android Programming. I need to display a Pop-Up message in my application which I have no clue about. I got to hear from somewhere that it can be done using alertdialog.builder, but I have no idea how to do that?
I just want to display a simple Text Message.
Can anybody please help me out regarding this with an example if possible.
If you want to display a simple message you're probably better off using a Toast.
Toast.makeText(this, "Some Text", Toast.LENGTH_LONG).show();
Or, if you're doing it properly, and using a String resource:
Toast.makeText(this, getString(R.string.message_toast), Toast.LENGTH_LONG).show();
If you really need a pop up that the user has to acknowledge by pressing a button, you can do something like this:
new AlertDialog.Builder(context).setMessage("message text").setPositiveButton("OK", null).setTitle("Title").show();
you can leave out setTitle if you don't need it