Android Button click being processed twice

Posted on 2011-10-04
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
    LVL 2

    Accepted Solution

    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 :)
    LVL 8

    Expert Comment

    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...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Free iPhone app to Watch free movie? 4 33
    Looking for JQM experts! 1 45
    Hybrid app to listen a radio 12 101
    Apps on mobile : future? 1 61
    Working settings for French ISP Orange "Prêt à Surfer" SIM cards for data connections only. Can't be found anywhere else !
    A short article about a problem I had getting the GPS LocationListener working.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now