按住一个按钮,使计数器每次都加1 [英] Keep pressing a button so that a counter keeps adding by 1 every time
本文介绍了按住一个按钮,使计数器每次都加1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在想是否有一种简单的方法可以按住同一个按钮,这样计数器每次都会增加1。因此,如果单击按钮两次,则计数器总计为2,因此允许第二个if语句起作用。
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 have a counter total of 2 therefore allowing the second if statement to function.
int counter = 0;
if(view.getId()=R.id.Spinbtn){
counter ++;
if(counter==2){
showcalcuation();
}
}
推荐答案
首先,让你的班级全球化:
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;
}
}
}
});
这篇关于按住一个按钮,使计数器每次都加1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文