I have buttons in my app that do various things. A problem i am running into is that a button can be pressed multiple times before what that button does is enabled/processed/calculated.
Example
when i press a button { an integer should have 1 added to it unless it is at it maximum value.
when i press a button { a dialog should show (only once).
in either case if i press slowly i have no problems, but if i press rapidly the integer will pass its maximum or multiple dialogs will show.
Can someone point me in the right direction to deal with this.
It sounds as though you could simply set a boolean value when the button handler is entered to signify that the task is being performed. If you enter the function and the value is already true then simply return (or just disable the button until the operation is complete).
I don't know a lot about android, and I don't know if you have the task running in a different thread or if multiple clicks are being queued up, in which case the boolean wouldn't help as it would all be happening in serial. In that case, as I suggested earlier, just disable the button while the task is in progress (probably a good idea in any case).
I would suggest disabling is not that user friendly, i see the user is selecting button and has a lot of time in between before the next operation happens and tats why he ends up clicking multiple times. In this case as soon as soon capture the click you can show circular progress dialog , that shows user something is in happening and he wont be able to click button also.
Dismiss the dialog once you have set the counter
or second case about to open the dialog ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "",
"Loading. Please wait...", true); then dialog.dismiss() once ur done
Related
I have a page where the user needs to enter their email and then hit a button at the bottom to confirm. While confirming the email, there is a ProgressDialog overlay on the screen. When an invalid email is entered into the EditText, like just entering the letter "a", an error message appears below the EditText in the form of a TextView. I am trying to make this page more accessible.
My intended approach is to have TalkBack mode focus in on the error text when it appears. However, this isn't quite working. Instead, when the ProgressDialog overlay is dismissed, nothing on the screen is selected by Talkback, I notice that the "confirm" button still appears to be in a selected state, and I hear the app announce the app name again, as if the Activity is getting recreated (though it is not). Swiping right at this point will select the first view on the screen. It's worth noting that the confirm button does not appear to hold the "selected" state when talkback mode is not turned on, like it does when talkback mode is turned on.
Here's the code that I've tried:
private fun onServerResult() {
...
dismissDialogOverlay()
if (error) {
showError(errorMessage)
}
}
private fun showError(msg : String?) {
mTvEmailError.text = msg
mTvEmailError.visibility = View.VISIBLE
mTvEmailError.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) //want focus now!
}
I have also tried mTvEmailError.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) and also tried pairing each with accessibilityEvent with mTvEmailError.requestFocus(). No luck.
What I'd like to have happen is for mTvEmailError to be the selected view in talkback mode. Instead, nothing is selected after the button press. It's as if Talkback mode gets completely lost after clicking on the confirm button.
mTvEmailError.postDelayed({ mTvEmailError.requestFocus() }, 300)
//Explanation
requestFocus function need to be called in a separate thread,if you call directly it will be called in the main thread,in main thread someother process may occur,if you call requestFocus() function traffic may occur,so we need to call in a separate thread with 300 milliseconds delay.
I had the exact same issue as OP, word for word.
Solved with this:
editTextObject.performAccessibilityAction(AccessibilityNodeInfo.ACTION_CLICK, null);
Now after the Dialog, the button that initiated the Dialog is unselected by Accessibility. Accessibility focus is on the EditText and TalkBack reads everything related to the EditText including the error message.
i have button in my first activity called Start.
Now when i click on this button it takes 1 to 2 seconds to load the next activity, now at that time the user clicks on the start button multiple times so what happens is that the next activity will open multiple times.
How to overcome this? Is there any way that even if the user clicks on the Start button multiple times open the activity only once.
Your Options:
On click, disable the button and display a ProgressDialog to the user.
Use the Intent flag FLAG_ACTIVITY_SINGLE_TOP to ensure only one activity is maintained on the stack. Documentation
Use the qualifer launchMode=singleInstance in your AndroidManifest.xml so only one instance of your Activity is allowed at a time. Documentation
I would recommend the first, because it can show the user your application is still working even if it takes a few seconds to do the necessary processing to begin your Activity.
You can put the launch mode of your 2nd activity as "Single Instance" in your manifest file.
Don't use anything like a launchMode or Intent flags. They are used for different purposes.
Description here
What you have to do is:
Show a progress dialog to clearly show the user that an
action(calling 2nd Activity) is in progress. This was user will not
try to click the button multiple times
Simply disable the button's click listener after 1st click. This is not
recommended because user might not be able to know whether he/she
clicked the button. Also this is the case where user tends to click
the button multiple times.
Good Morning,
I have a list of items with a prev. & next button. When the user is at the start of the list the prev button is disabled. Clicking next takes them to the next record and my click handler sets the prev button enabled true. However in the emulator it doesn't show the button enabled. Clicking next moves me to the third record and again the handler sets the prev button enabled but this time it does become enabled in the emulator. I'm grasping at straw here but do I need to invalidate and redraw or something?? I don't understand why such an elementary task is not working.
In XML:
<Button
android:id="#+id/btn_PrevLift"
...
android:enabled="false"
android:onClick="btn_PrevLiftClick" />
In the handler code:
private void UpdateNavButtonStatus(int z)
{
...
btn_Next.setEnabled(true);
btn_Prev.setEnabled(true);
....
}
No just to show you how little I know about what I'm doing how come when I look at the variable values in Eclipse debug I can't see the enabled property in any state???
More Info
Very odd to me at least. If I move from using XML defined event handlers to programatically defined as below it works great!!!???
btn_Nxt.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//Call helper methods etc...
}
});
I think I have it but not sure exactly why
So when I was trying to get a handle on my Button objects I was using the View.findViewById(etc). When I changed from XML to the programatically declared event handler I used ViewGroup.findViewById. Reverting back to xml if I use the ViewGroup I get a "different" handle that seems to work...????
Ok,so what you can do is declare a variable count and on the click f button next increment the value of count..and on the click of Back button decrement the value of count and give the condition that while count<0 the task of the back button is done else nothing
I have identified the problem and of course the problem is me. I was enabling the button and then the ListView was updating to the next record. Of course my enabled button was one behind so it appeared that when I clicked a second time the button suddenly enable but that is not the case. When I clicked a second time we moved to record three and showed button for record two which was enabled.
See my buttons were part of my ListView and new buttons were being drawn for each record. OOHHHH it makes so much sense now how everything was behaving.
Anyway I moved the buttons off the ListView layout so they remain constant as the user navigates through the records.
Here is my problem - I want to create an activity and a dialog (with text field and OK button). I want to do the following:
Show the AlertDialog (on creation of the activity, on clicking a button, or some other actions);
Fill the text in the AlertDialog, and click the OK button;
Continue doing the main thread of the activity;
Something like this:
public String getText() {
String result = null;
// Showing the new window with the text box and the button, and after
// the button is clicked to move to the return statement below;
return result;
}
I tried using "runOnUiThread" and "AsyncTask", but the actions on the field "result" are done only in the "protected void onPostExecute(Void result)" method, and meanwhile the main program is still executing, without waiting for my input.
Is there anyway this to be done (I am sure it has, because saw such apps) to solve this problem? I know that is really impudent to ask for such help - but is is possible to write some code example, just to see how it is really happening, because more than 3 days, I can' do it. If not please give some suggestions, and will continue trying and trying :)
THANKS A LOT!
Whatever the operations u want to perform after click ,write in asynctask .When dialog button clicked execute the asynctask.Thats it
Well that's pretty much how dialogs work anyway.
http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
At the bottom it shows how to create a custom dialog.
However, a lot of the time the text you need to take in is also displayed on the activity anyway, could you not embed an EditText on your activity and simplify this task?
I have an activity that starts on demand of the user.
The user can demand it from several activities.
The thing is I want to give the user an explanation before he has to handle that activity.
I thought about creating a Dialog, giving the user only an OK button to tap on.
But It will be ugly because:
It has to return a value (in my case there is no value I have to return)
The Dialog will have to start the new activity, then when the user presses 'back' button, it will return to the Dialog
Also, if I choose to return to the activity that showed the dialog and start the new activity from there, I'll have to do this in several places (like I explained in the second line of this questions)
Any ideas?
Thanks!
Not sure what you mean by 1. but if you call dismiss() in the onClickListener that handles your OK button, it will not be shown again after you come back from the started activity when you press the back button.
Do make it easier to reuse the dialog, you should create a custom class that handles the dialog. Then you can easily show the dialog from different activities.