2015-11-18 48 views
0

为什么可以改变背景颜色,但它不是设置 新文本????得到所有RadioGroup中选择ID

RadioGroup allRadioGroups[] = {button1, button2}; 

为什么我能做到这些的:

allRadioGroups[0].getChildAt(1).setBackgroundColor(Color.parseColor("#216059")); 

allRadioGroups[1].getChildAt(3).setEnables(false); 

,但我不能做这些的:

allRadioGroups[0].getChildAt(1).isChecked(); 

allRadioGroups[1].getChildAt(3).setText("My Text"); 

回答

0

但我不能做这些的:

allRadioGroups[0].getChildAt(1).isChecked(); 
allRadioGroups[1].getChildAt(3).setText("My Text"); 

因为getChildAt方法的返回View对象。 isCheckedsetText方法不是从类(单选)View class.these方法延伸View类

因此,要获得这些线路Cast的回报ViewRadioButton

((RadioButton)allRadioGroups[0].getChildAt(1)).isChecked(); 
((RadioButton)allRadioGroups[1].getChildAt(3)).setText("My Text");