我变得像这样,它不仅应该显示在特定项目上如何将自定义列表视图中的单选按钮设置为单一模式。如果我单击特定单选按钮,则它必须出现,而另一个未选中。如果单击第一行,则选中第一行上的单选按钮。单击第二行上的第二行单选按钮,选中第二行,未选中第一行。单击第三行选中第三行单选按钮,未选中第一行和第二行。
自定义列表.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:text="" /> <TextView android:id="@+id/card" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="10dip" android:layout_centerVertical="true" android:layout_toRightOf="@+id/radioButton1" android:text="" android:textColor="#000000" android:textSize="15dip" android:textStyle="bold" /> </RelativeLayout> listView = (ListView) findViewById(R.id.cardlist); adapter =new MyAdapter(this, app.arryList,app.arryList1); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "am thelist",Toast.LENGTH_LONG).show(); } }); listView.setAdapter(adapter); listView.setChoiceMode(listView.CHOICE_MODE_SINGLE); } public class MyAdapter extends BaseAdapter { Context context = null; ArrayList<String> items= null; ArrayList<String> items1= null; public MyAdapter(Newcard newcard, ArrayList<String> items, ArrayList<String> items1) { // TODO Auto-generated constructor stub this.items = items; this.items1 = items1; } @Override public int getCount() { // TODO Auto-generated method stub return items.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return items; //return items.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View layout = null; TextView produ = null; TextView desc = null; Button edit = null; RadioButton radio =null; if (convertView == null) { lay = LayoutInflater.from(getApplicationContext()); layout = lay.inflate(R.layout.customlist, null); } else { layout = convertView; } produ = (TextView) layout.findViewById(R.id.card); produ.setText("" +app.arryList.get(position)); radio = (RadioButton) layout.findViewById(R.id.radioButton1); radio.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //check.setVisibility(View.GONE); System.out.println("data "+app.arryList.get(position)); } }); } }); return layout;