Keep pressing a button so that a counter keeps adding by 1 every time

前端 未结 2 607
情歌与酒
情歌与酒 2021-01-29 09:12

I was thinking if there was a simple way to keep pressing the same button so that the counter keeps adding by 1 every time. So that if the button is clicked two times it will ha

2条回答
  •  天涯浪人
    2021-01-29 09:52

    First, make this global within your class:

    int counter = 0;  
    

    Then implement the button click event:

     final Button button = (Button) findViewById(R.id.Spinbtn);
              button.setOnClickListener(new View.OnClickListener() {
                   public void onClick(View view) {
                        if(view.getId() == R.id.Spinbtn){
                             if(counter == 2){
                                showcalcuation();
                             }else if(counter < 2){
                                counter += 1;
                             }
                        }
                   }
              });
    

提交回复
热议问题