Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Android Button click being processed twice

Posted on 2011-10-04
Medium Priority
Last Modified: 2013-09-29
I have a submit button on a form that submits the form.  The problem is, if the user double clicks or taps on the button it is getting processed multiple times.  I have tried to deactivate the button the first time it is selected but then the button does not process at all on Android 2.2 but seems to work on more current versions.  What is the best way to ensure that the button is only selected once.
Question by:nvbob

Accepted Solution

yianniscy84 earned 2000 total points
ID: 36957084
An easy way that just popped in my head is to increase a counter every time the button is pressed and process the request only if counter=1 :)

Expert Comment

ID: 37690088
hi  nvbob,

Implement both onClick and onTouch listener for the button.
And set a flag in class level

private static boolean mIsButtonClicked = false;

public boolean onTouch(View aView, MotionEvent aEvent){
              if(aEvent.getAction() == MotionEvent.ACTION_DOWN){
                          mIsButtonClicked = true;
              if(aEvent.getAction() == MotionEvent.ACTION_UP){
                          mIsButtonClicked = false;
            return false;
public void onClick(View aView){
              //Do ur things here

I thing in this way u can ensure that only one time u r button is selected...

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question