【发布时间】:2011-12-23 14:12:05
【问题描述】:
我目前正在自定义列表视图,其中我扩展了数组适配器并使用它的 getview 方法显示每一行,单选按钮位于最右侧,项目名称位于每行左侧,现在我想将所有单选按钮放入无线电组,以便一次只选择其中一个,但我遇到 java.lang.IllegalStateException 异常:指定的孩子已经有一个父母。您必须先在孩子的父母上调用 removeView()。
这里是创建此错误的基本代码 sn-p。
类 MyCustomAdapter 扩展了 ArrayAdapter 并在 getView()
if (row==null)
{
row=inflater.inflate(R.layout.row, parent, false);
RadioButton toggle1=(RadioButton)row.findViewById(com.example.ToggleButtonExample.R.id.toggle_id);
//this is radio button which i had created in row.xml
radio1.addView(toggle1); //create error here
}
【问题讨论】:
标签: android