标签:listview radiobutton 单选模式 singlechoice
来源:https://stackoverflow.com/questions/8337180/custom-single-choice-listview/12823457#12823457
<span style="font-size:18px;"><RadioButton android:id="@+id/radio1" android:checked="false" android:focusable="false" android:clickable="false" /></span>
<ListView android:id="@android:id/list" android:choiceMode="singleChoice" android:descendantFocusability="beforeDescendants" />
int selectedIndex = -1; public void setSelectedIndex(int index){ selectedIndex = index; } @Override public View getView(int position, View convertView, ViewGroup parent) { RadioButton rbSelect = (RadioButton) convertView .findViewById(R.id.radio1); if(selectedIndex == position){ rbSelect.setChecked(true); } else{ rbSelect.setChecked(false); } }
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mChangeAdapter.setSelectedIndex(position); mChangeAdapter.notifyDataSetChanged(); } });
ChangeBean bean = mData.get(position); mHolder.tv_name.setText(bean.name); if (selectedIndex == position) { mHolder.iv_choice.setChecked(true); bean.setCheck(true); updateData(bean); } else { mHolder.iv_choice.setChecked(false); bean.setCheck(false); updateData(bean); }
mChangeAdapter = new ChangeAdapter(this); mList.setAdapter(mChangeAdapter); initSelect(); mChangeAdapter.refresh(mDatas); addListener(); } private void initSelect() { for (int i = 0; i < mDatas.size(); i++) { if (mDatas.get(i).check){ mChangeAdapter.setSelectedIndex(i); return; } } }
超简单的listview单选模式SingleMode(自定义listview item)
标签:listview radiobutton 单选模式 singlechoice
原文地址:http://blog.csdn.net/qq634416025/article/details/45112539