我试图将自动生成的单选按钮放入无线电组并尝试格式化。我有一个额外的活动,有一个单选按钮,我可以格式化单个单选按钮。我找不到另一种方法来改变x app:buttonTint="@android:color/holo_green_light"
。
这是我的示例代码:
1: Radiogroup group;
2. group = (RadioGroup)findViewById(R.id.radiogroup);
3: LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
4: final View item = layoutInflater.inflate(R.layout.testactivity, null);
5: RadioButton addradiobutton = (RadioButton)item.findViewbyId(R.id.rb_from_other_activity);
6: group.addView(addradiobutton);
程序在第6行崩溃。我不确定,但我猜addradiobutton
不是“真正的”RadioButton。
以下是第6行的致命异常:
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.user.name.app/de.user.project.app.activity}: java.lang.IllegalStateException:
The specified child already has a parent. You must call removeView() on the child's parent first....
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.