我有一个自定义列表视图,其中填充了单选按钮和文本视图。我为listview实现了onListItemClick监听器。我的问题是我想在列表视图中单击一行时检查单选按钮,但所有行单选按钮状态更改为true。我无法弄清楚原因 onListItem Listener片段
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();
}
});
请提供建议
答案 0 :(得分:0)
尝试覆盖适配器的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;
}