Dialog.Confirm that returns boolean in Android - android

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.

Related

How to add "show text" in Android(x) password preference dialog

There doesn't appear to be a specific password text dialog in the Androidx (or Android) library.
I want to add a button so that the user can switch between text view and password text view (asterisks instead of letters) for this preference even though, as someone might want to tell me, it's not a fabulous idea to store passwords as preferences. Eventually I'll have a more robust approach but in the meantime this is what I've got.
I'm using the code that Android Studio (generously) offers me for "Preference Activity". In all other respects it seems pretty good, and better than I can manage myself yet. It's just got this (annoying lack of) feature.
This question is a little too old to reference Androidx, and according to the (main) relevant answer to my context, I can't use AndroidX here. However, using the code from the Settings Activity I don't explicitly mention DialogPreference at all.
So, is there a way to slot in a "reveal" button in this situation, or should I either not use the "textPassword" input type, or completely rebuild this activity?
I was messing round with something similar the other day. I didn't use a reveal button, but just got it to never show the password:
input_password.setText(prefs.getYourPassword().toAsterix())
private fun String.toAsterix(): String {
return replace("[.]", "*")
}
With a PreferenceActivity, you would have to make a custom view. It would be an EditText and a Button. Clicking the button would set the text to either prefs.getYourPassword() or prefs.getYourPassword().toAsterix().

Android show newest toast

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();

email: Which are Intent.ACTION_SEND return values?

When I launch
startActivity(new Intent(Intent.ACTION_SEND))
for sending an email, which are the returned values that I can test in the
onActivityResult(){...}
?
Because (for example):
if the user exit the email client clicking su "Cancel", I want execute methodX(...)
otherwise i will execute methodY(...)
But to perform that, I need to know the Intent returned values. Is it possible?
I don't think this is specified.
You can't be sure which Activity will end up handling your intent, and each Activity could return different resultCodes for the same logical outcome.
In my testing the text messaging app in the emulator returned zero no matter the outcome.
I know it is a bit of a cludge but why not use the H-API (Human Application Programming Interface) to determine if it was sent. Pop up a dialog and ask them "Did you send the email?" or "Was the email sent OK?". Or add a required checkbox to the calling view "Email Sent?" and ensure it is checked before allowing the user to continue.
We try to "save" the user from having to interact as much as possible but I'm not convinced that is necessarily what they want. Not all solutions have to be solved with technical workarounds. Devs forget that sometimes.

What do you do to protect the user from a dangerous button in Android?

I have an app out that involves keeping track of information over time. Part of the app is a reset button. In order to avoid accidental resets, I made that button respond only to long-clicks. However, that approach confused about 20% of my new users, who thought that the reset button must not be working.
Is there a more intuitive (and standard) way to protect a button from accidental presses? (If not, I can add some sort of custom message to the button I have . . . )
A Thilo said, a confirmation dialog is the standard answer.
This is good reading if you haven't already:
http://www.codinghorror.com/blog/2010/03/the-opposite-of-fitts-law.html
Basically, make it small! Long click is a good answer, but unless there's a "press and hold" label right underneath that, users are going to have trouble - that violates the user model, since users aren't used to having to do that (I probably wouldn't be able to figure it out).
On the iPhone it's fairly standard to have "slide" buttons (like the unlock) for operations like this, since it's much more difficult to accidentally slide. You could implement something similar to that, but it might be overkill for this problem.
Another vote for Thilo and a confirmation dialog.
Also Google/Android is trying to get devs to use the long press as a Quick Action UI pattern. See Android Developers Blog entry on Twitter app
All though this is kinda a workaround, it still works.
case R.id.bReset:
long startTime = System.nanoTime();
boolean running = true;
//show dialog with a single button - cancel. Outside the loop. Upon cancel, set cancelled to true.
//You can use DialogFragment or AlertDialog
while(running && !canceled){
long elapsed = (System.nanoTime() - startTime) / 1000000;
if(elapsed > securityTime && !canceled) {//set security time to amount of seconds * 1000
//Dismiss dialog
//reset
}
}
break;
From the currently accepted answer:
As Thilo said, a confirmation dialog is the standard answer.
It does not have to be a confirmation dialog, but if accidental press the user should have the opportunity to cancel the action while at the same time no further action is required if the user wanted to do it.

Android: need to validate an edittext for non-blank input

If I want to enforce a maximum length of input in an EditText field, I can use the maxLength attribute. But if I want to enforce a minimum length (in my case, simply non-blank), I find no corresponding minLength attribute.
I've also looked at the various 'inputType' attributes (phone, password, etc) but I don't see anything like 'required' or 'non-blank'.
I can't believe this would require a custom input filter; it's more likely the answer is so obvious it just doesn't get written down in the form I'm asking the question.
You can simply check that yourField.text() is not equivalent to null or "" at the point of submission. If it is, prompt the user to input something.
Carefull with something though. If you have a submit button, for instance, and your user presses submit without changing the focus out of your TextEdit, your method won't be called.
Take an Activity with 2 EditTexts and 1 button named "Go":
1) User writes something in EditText1
2) User clicks on EditText2
3) Instead of writting something there just clicks go.
Your onFocusChanged() method won't be called because focus is not "lost".
If you have a validation in your Go button_click method, it will trigger, of course, but you won't achieve your goal "I was looking/hoping for was a way to give instant feedback"
You can try using TextWatcher.

Categories

Resources