【发布时间】:2012-08-02 16:31:25
【问题描述】:
我遇到了一个错误,我不明白它是什么意思。我是 Android 新手
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
我正在尝试以编程方式将单选组添加到表格布局中
首先我将单选组添加到表格布局中,然后将单选按钮添加到单选组
RadioGroup mRadioGroup;
mRadioGroup = new RadioGroup(this);
TableLayout mainTable = (TableLayout) findViewById(R.id.myTable);
mainTable.addView(mRadioGroup);
然后我创建一个行并将单选组添加到该行,最后将该行添加到表格布局中
TableRow row;
RadioButton radioButton = new RadioButton(this);
radioButton.setId(1);
radioButton.setText("SomeText");
row.addView(mRadioGroup);
mainTable.addView(row);
有人可以帮忙吗?
编辑:当我将收音机组直接添加到表格布局而不是表格行时,它起作用了
【问题讨论】:
标签: android android-layout radio-button radio-group