Java If循环过多的单击无法重置

Java If循环过多的单击无法重置,java,android,loops,if-statement,Java,Android,Loops,If Statement,我有一个按钮,当点击时,它应该计数,直到它达到resetTouch限制,然后重置为0 然而,事实并非如此 int resetTouch = 4; int number = 1; int touches1 = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setCon

我有一个按钮,当点击时,它应该计数,直到它达到resetTouch限制,然后重置为0

然而,事实并非如此

    int resetTouch = 4;
    int number = 1;
    int touches1 = 0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


    }

    //adds number of touches
    public void setTouches1 (View view){

        if (touches1 < resetTouch){
           touches1 = touches1 + number;

           displayTeamTouches(touches1);
}
           else{
            touches1 = 0;
        }
int resetTouch=4;
整数=1;
int touches1=0;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//添加触摸次数
公共无效集合接触1(视图){
如果(触摸1<重置触摸){
触摸1=触摸1+数字;
显示团队触摸(触摸1);
}
否则{
触摸1=0;
}
此排序有效,但不是在3处停止,而是变为4。此时我必须单击+按钮两次,使其重置为1。我希望它增加到3,然后重置为0


我做错了什么?

当你观察
触摸1时,它已经增加了。你的第一次跑步看起来像1、2、3、4,然后它会重置

在增加变量之前,应该先观察它。这样,实际上可以看到0、1、2、3

if(touches1 < resetTouch) {
    displayTeamTouches(touches1);
    touches1 += number;
}
if(触摸1
touches1++;或touches1+=number;谢谢。它正在正确重置,但在重置之前,它会在3处停留两次单击。