本次设计的思想是利用listview的item单击动作控制RadioButton的显示
mail.xmlitem.xml:在item行的样式设计中,最重要的是要阻断item中控件的事件android:descendantFocusability="blocksDescendants";并且将RadioButton的clicable设置为false。
.java
private int clickPosition = -1;
@Override public View getView(int arg0, View arg1, ViewGroup arg2) { // TODO Auto-generated method stub ViewHolder holder = null; if (arg1 == null) { holder = new ViewHolder(); arg1 = mInflater.inflate(R.layout.chooselanguage_item, null); holder.title = (TextView) arg1.findViewById(R.id.title); holder.RadioBtn = (RadioButton) arg1 .findViewById(R.id.radiobutton); arg1.setTag(holder); } holder = (ViewHolder) arg1.getTag(); holder.title.setText((String) mData.get(arg0).get("title")); // holder.RadioBtn.setChecked((Boolean)mData.get(arg0).get("choice")); if (clickPosition == arg0) { holder.RadioBtn.setChecked(true); } else { holder.RadioBtn.setChecked(false); } return arg1; } }
@Override public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub clickPosition = arg2; mAdapter.notifyDataSetInvalidated(); }