我需要用到很多Button控件,所以想定义一个数组。
先声明了
Button []button;
再取得Button对象时就报错,是不是要先new一个对象?
button[0]=(Button)findViewById(R.id.btton01);
button[1]=(Button)findViewById(R.id.button01_1);
button[2]=(Button)findViewById(R.id.button01_2);
button[3]=(Button)findViewById(R.id.button01_3);
button[4]=(Button)findViewById(R.id.button01_4);
先声明了
Button []button;
再取得Button对象时就报错,是不是要先new一个对象?
button[0]=(Button)findViewById(R.id.btton01);
button[1]=(Button)findViewById(R.id.button01_1);
button[2]=(Button)findViewById(R.id.button01_2);
button[3]=(Button)findViewById(R.id.button01_3);
button[4]=(Button)findViewById(R.id.button01_4);
是需要先new一个button对象。
没写的话,就必须new一个button了
private ArrayList<Button> mlist = new List<Button>();
mlist.add((Button)findViewById(R.id.btton01));
mlist.add((Button)findViewById(R.id.button01_1));
mlist.add((Button)findViewById(R.id.button01_2));
mlist.add((Button)findViewById(R.id.button01_3));
mlist.add((Button)findViewById(R.id.button01_4));