我在该复选框中有一个自定义列表视图,并且存在文本视图..
如果我单击第 1 行复选框,则仅选中该行咀嚼框。如果我单击第二行,则选中第二行复选框,未选中第一行。如果单击第三行,则选中第三行复选框,未选中第二行...
所以只需要选择特定的行点击项目复选框......
但是这里所有的复选框都在选择...如何解决这个问题..
包 com.example.testdata;
public class Newcard extends Activity {
MyAdapter adapter;
CheckBox check=null;
ListView listView;
LayoutInflater lay;
MyApplication app;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.newcard);
app = ((MyApplication) getApplicationContext());
listView = (ListView) findViewById(R.id.cardlist);
adapter =new MyAdapter(this, app.arryList);
listView.setAdapter(adapter);
listView.setChoiceMode(listView.CHOICE_MODE_SINGLE);
}
public class MyAdapter extends BaseAdapter {
Context context = null;
ArrayList<String> items= null;
public MyAdapter(Newcard newcard, ArrayList<String> items,
ArrayList<String> items1) {
// TODO Auto-generated constructor stub
this.items = items;
}
@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;
}
@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;
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));
check = (CheckBox) layout.findViewById(R.id.radioButton1);
check.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// System.out.println("data "+app.arryList.get(position));
}
});
return layout;
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<CheckBox
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>