本文介绍了如何初始化意见(的ToggleButtons)阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个活动11的ToggleButtons,而在此刻,在我的onCreate申报11的ToggleButtons一个数组,我在的onCreate(定义),这样的:
I have 11 ToggleButtons in an activity, and at the moment, in the onCreate I declare an array of 11 ToggleButtons, that I define in onCreate(), like that:
private static ToggleButton toggleButton[] = new ToggleButton[11];
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toggleButton[0] = (ToggleButton) findViewById(R.id.ToggleButton00);
toggleButton[1] = (ToggleButton) findViewById(R.id.ToggleButton01);
toggleButton[2] = (ToggleButton) findViewById(R.id.ToggleButton02);
toggleButton[3] = (ToggleButton) findViewById(R.id.ToggleButton03);
toggleButton[4] = (ToggleButton) findViewById(R.id.ToggleButton04);
toggleButton[5] = (ToggleButton) findViewById(R.id.ToggleButton05);
toggleButton[6] = (ToggleButton) findViewById(R.id.ToggleButton06);
toggleButton[7] = (ToggleButton) findViewById(R.id.ToggleButton07);
toggleButton[8] = (ToggleButton) findViewById(R.id.ToggleButton08);
toggleButton[9] = (ToggleButton) findViewById(R.id.ToggleButton09);
toggleButton[10] = (ToggleButton) findViewById(R.id.ToggleButton10);
我相信应该有更好的方式(如循环),任何想法?你会怎么做呢?
I'm sure there should be a better way (like a loop), any idea? How would you do that?
推荐答案
试试这个code:
ToggleButton toggleButton[] = new ToggleButton[11];
int arrayindex = 0;
int viewcount = 0;
while (arrayindex < 11) {
View v = asyncLayout.getChildAt(viewcount);
if (v instanceof ToggleButton) {
toggleButton[arrayindex] = (ToggleButton) v;
arrayindex ++;
}
viewcount ++ ;
}
喂我回来的任何问题。
feed me back in any issue
这篇关于如何初始化意见(的ToggleButtons)阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!