Single click and double click of a button in android

前端 未结 9 1332
遇见更好的自我
遇见更好的自我 2020-12-05 22:09

In my application i have a button. After single and double clicking of the button will perform separate operation. How can i do that? Thanks

9条回答
  •  不知归路
    2020-12-05 22:18

    I also got the same problem once

    setOnClickListener(new OnClickListener() {           
                @Override
                public void onClick(View v) {
                    if(isFmOn()){
                       //stopFM
                    }else{
                      //do other things
                    }
                }
    }
    

    when I clicked the Button,FM stopped;but when I double clicked,FM did not stop.The problem was that single and double clicking of the button ,the value of isFmOn() was difference. I sloved the problem using this:

    setOnClickListener(new OnClickListener() {           
                @Override
                public void onClick(View v) {
                    Thread.sleep(500);//500ms was enough to finish stopFM before the second click
                    if(isFmOn()){
                       //stopFM
                    }else{
                      //do other things
                    }
                }
    }
    

提交回复
热议问题