2
我正在創建一個應用程序來發送聯繫人。我通過使用帶有名稱編號和複選框的自定義適配器填充了列表視圖來顯示聯繫人詳細信息。問題是當我檢查一個複選框隨機複選框也被選中列表中。我在這裏refered這麼多的問題和STIL它不工作Android listview檢查多個項目,同時選擇複選框
方法在適配器類填充列表
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ContactsBean contact = contacts.get(position);
ViewHolder holder = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mainActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_layout, null);
holder = new ViewHolder();
holder.number = (TextView) convertView.findViewById(R.id.numberTextView);
holder.name = (TextView) convertView.findViewById(R.id.nameTextView);
holder.box = (CheckBox) convertView.findViewById(R.id.checkBox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(contact.getName());
holder.number.setText(contact.getNumber().get(0));
holder.name.setTag(contact);
holder.box.setTag(contact);
holder.box.setOnClickListener(this);
holder.box.setSelected(contact.isSelect());
return convertView;
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.checkBox) {
ContactsBean bean = (ContactsBean) v.getTag();
bean.setSelect(!bean.isSelect());
notifyDataSetChanged();
}
}
private static class ViewHolder {
public TextView number;
public TextView name;
public CheckBox box;
}
這裏是我的觀點[輸入鏈接描述](http://stackoverflow.com/questions/6470089/why-did-the-listview-repeated-every-6th-item/41900575#41900575) – Sam