I've created a DialogFragment and used getDialog().setTitle("Application failed to decrypt the file") and the thing I see in the title is "Application failed to". Is there a limitation for a title? How can I put the whole string in it? Thanks.
use an AlertDialog to show a message instead for something this long.
Related
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();
I have created a MultiSelectListPreference. It does not show ANY multi-selection list, of the default_aliases. It only shows the text "Choose aliases" (dialogMessage) in the opened dialog.
<MultiSelectListPreference
android:title="#string/aliases"
android:positiveButtonText="#android:string/ok"
android:negativeButtonText="#android:string/cancel"
android:dialogTitle="Aliases"
android:key="aliases"
android:dialogMessage="Choose aliases"
android:defaultValue="#array/default_aliases"
android:entryValues="#array/default_aliases"
android:entries="#array/default_aliases"/>
MultiSelectListPreference, being a DialogPreference, has the inherited "dialogMessage" attribute. You would think this message should be an explanation (for the user) on the selection - but NO. The dialog widget simply shows JUST the message, and totally ignores the multi-selection part.
The solution is not to supply a "dialogMessage" at all.
This is a weird behavior, and looks a bit like an Android bug. I am using api 15 (4.1).
I'm trying to add a string to the following alert box's positive button, but it keeps spamming out error messages.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.checkNetwork).setTitle(
R.string.checkNetworkTitle);
builder.setIcon(R.drawable.ic_warning);
builder.setPositiveButton(android.R.string.continue, new warningContinue());
AlertDialog dialog = builder.create();
dialog.show();
Any help? It does seem to work for the title and the message, however not for the button...
Thanks in advance.
EDIT: The error says:
The method setPositiveButton(int, DialogInterface.OnClickListener) in
the type AlertDialog.Builder is not applicable for the arguments
(Class, warningContinue)
So it seems to expect an integer, but I was wondering if there's any way to use strings for localization-purposes?
EDIT2:
Ok what the hell. Problem lied in the string name; it won't let me name my string continue for some reason. o_O
You don't want to use "android.R.string.continue". "package name".R.string.continue is what you want. Thats the usual way you're doing localization in android. The id provides multilanguage support automatically based on the users system language. You just have to create multiple "values" directories. https://developer.android.com/guide/topics/resources/localization.html provides you more information about localization.
Also you can't use "continue" as a name, use "str_continue" or something like that (it's the same for "return" or "break" ect.). They are reserved in java. For more information you could read the link: http://java.about.com/od/javasyntax/a/reservedwords.htm
Because you don't post the code of "warningContinue()", i think you know that it has to extend "DialogInterface.OnClickListener()". Also you should consider to write your classes first character uppercase for convention reasons, for more information read this answer on stackoverflow: https://stackoverflow.com/a/414029/2238341
R.string.warningButton is just the int in your R.java file. To get the associated string use the following line:
builder.setPositiveButton(getString(R.string.warningButton), new warningContinue() );
As other mentioned, don't use android.R.string.continue as it doesn't exist in system.
try, first go to res / values / strings.xml and declare your string as follows
<string name="checkNetwork">your String...</string>
Then you can take it as follows
R.string.checkNetwork
Just like this one and be happy ....
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