我在该复选框中有自定义列表视图并且存在textview ..
如果我点击第1行复选框,则仅检查该行chewk框。 如果我点击第二行,则选择第二行复选框 如果我单击第三行,则第三行复选框是未选中的行 选中和第二行未被选中......
只需选择特定的行点击项复选框...
但是这里的所有复选框都在选择...如何解决这个问题..
package 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>
答案 0 :(得分:0)
上面的代码不完整,我看不到你在哪里创建表单/复选框。但是,我看到这一行:check = (CheckBox) layout.findViewById(R.id.radioButton1);
您可能正在使用radiobuttons并将它们转换为复选框? Radiobuttons用于选择多个选项中的一个,例如您的行为。您需要确保创建了复选框而不是单选按钮来解决问题。