【问题标题】:Adding radio button of customize listview in radio group在单选组中添加自定义列表视图的单选按钮
【发布时间】: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


    【解决方案1】:

    您好,首先您需要将单选按钮添加到单选组,然后通过下面的链接进入列表视图,这将对您有所帮助。radiogroup issue

    【讨论】:

      猜你喜欢
      • 2012-08-04
      • 2014-02-16
      • 2019-02-16
      • 1970-01-01
      • 2013-03-10
      • 2014-01-09
      • 2013-01-14
      • 1970-01-01
      • 2013-10-10
      相关资源
      最近更新 更多