【问题标题】:setting checked state for radio button inside custom list view为自定义列表视图中的单选按钮设置选中状态
【发布时间】:2013-03-28 16:53:51
【问题描述】:

我有一个自定义列表视图,其中填充了单选按钮和文本视图。我已经为 listview 实现了 onListItemClick 侦听器。我的问题是我想在单击列表视图中的一行时检查单选按钮,但所有行单选按钮状态都更改为 true。我无法弄清楚原因 onListItem 监听器 sn-ps

                listView.setOnItemClickListener(new OnItemClickListener() 
            {
                @Override
                public void onItemClick(AdapterView<?> arg0, View rowView,
                        int pos, long id) 
                {
                    rbChgPlan = (RadioButton) rowView.findViewById(R.id.radioButton);
                    rbChgPlan.setChecked(true);
                    planId= newPlans.get(pos).plan_id;

                    adapter.notifyDataSetChanged();
                }
            });

请提供建议

【问题讨论】:

  • 创建 RadioButtonas final

标签: android android-listview radio-button onitemclicklistener


【解决方案1】:

尝试覆盖适配器的 getview 方法。

public View getView(final int position, View convertView, final ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.masterlist, null);
    }
    rbChgPlan  = (RadioButton) v.findViewById(R.id.ckbox1);
    rbChgPlan.setChecked(true);
});
return v;
}

【讨论】:

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