如何在按钮单击内创建循环

时间:2015-07-18 10:14:56

标签: android textview android-button

我有1 buttontext view。 我想在每次点击0-5时显示text view中的号码button

int index = 2;

                    switch (index) {
                        case 0:
                            // if we are using index 0, set the text to index 1 text and change index to 1
                            index = 1;
                            line2.setText(0);
                            break;
                        case 1:
                            index = 2;
                            line2.setText(1);
                            break;
                        case 2:
                            index = 0;
                            line2.setText(2);
                            break;
                    }

我曾尝试过互联网上提供的大多数示例,但它没有改变价值。 任何人都可以帮我解决这个问题。

先谢谢。

1 个答案:

答案 0 :(得分:2)

int mCounter = 0;

按钮 onClick()

if(mCounter>4){
     mCounter=0;
 }
mCounter++;
txtInfo.setText(""+mCounter);

希望它会对你有所帮助。