这是我的联系人选择列表活动,其中包含联系人列表。我想通过复选框选择多个联系人并将数据发送给他们。 问题是:当我检查一个联系人并向下滚动列表视图时,我回来自动向上滚动选中的复选框
这是我的联系人选择器活动:
if (cb.isChecked()) {
Log.i("in if check box", receiver_id+"++++");
obj_Send_data = new send_data();
obj_Send_data.setReceiver_id(receiver_id);
obj_Send_data.setGcm_reg_id(gcm_reg_id);
id_arrArrayList.add(obj_Send_data);
Log.i("arraylist in if lisze", "++"+ id_arrArrayList.size());
Log.i("array list obj","++"+obj_Send_data);
} else if (!cb.isChecked()) {
id_arrArrayList.remove(obj_Send_data);
Log.i("arraylist in else lisze", "++"+ id_arrArrayList.size());
}
================================================================================================
here my custom listview adapter
================================================================================================
public class CustomListViewAdapter extends BaseAdapter {
Context cm1;
ArrayList<PhoneContactInfo> itemdetails,arraylist;
LayoutInflater l_inflater;
String[] str;
ArrayList<String> image1;
int[] intarray_;
boolean[] itemChecked;
/* List<Registure_user> registure_user_list;*/
private static class ViewHolder {
public ImageView imageView;
public TextView name,number;
CheckBox ch;
}
public CustomListViewAdapter(Context context,ArrayList<PhoneContactInfo> list,List<Registure_user> registure_user,ArrayList<String> image) {
cm1=context;
itemdetails=list;
l_inflater=LayoutInflater.from(context);
image1=image;
// registure_user_list=registure_user;
arraylist=new ArrayList<PhoneContactInfo>();
arraylist.addAll(list);
itemChecked = new boolean[arraylist.size()];
}
public int getCount() {
return itemdetails.size();
}
public Object getItem(int arg0) {
return itemdetails.get(arg0);
}
public long getItemId(int arg0) {
return arg0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
View vi = convertView;
if(vi==null)
vi = l_inflater.inflate(R.layout.custcontactview, null);
holder = new ViewHolder();
holder.number = (TextView) vi.findViewById(R.id.txtContactNumber);
holder.name= (TextView) vi.findViewById(R.id.txtContactName);
holder.imageView = (ImageView) vi.findViewById(R.id.imageView1_icon);
holder.ch=(CheckBox) vi.findViewById(R.id.checkBox1_check);
holder.ch.setClickable(false);
holder.name.setText(itemdetails.get(position).getcontactName());
holder.number.setText(itemdetails.get(position).getcontactNumber());
if(!image1.get(position).equals("0")){
holder.imageView.setVisibility(View.VISIBLE);
holder.ch.setVisibility(View.VISIBLE);
vi.setTag(image1.get(position)+" ");
holder.ch.setTag(vi.getTag());
Log.i("tag", vi.getTag()+"==");
}
else {
holder.imageView.setVisibility(View.INVISIBLE);
holder.ch.setVisibility(View.INVISIBLE);
vi.setTag("0");
}
return vi;
}
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
itemdetails.clear();
if (charText.length() == 0) {
itemdetails.addAll(arraylist);
} else {
for (int i=0;i<arraylist.size();i++ ) {
if (arraylist.get(i).getcontactName().toLowerCase(Locale.getDefault())
.contains(charText)) {
Log.i("serch", arraylist.get(i).getcontactName());
itemdetails.addAll(arraylist);
}
}
}
notifyDataSetChanged();
}
}
答案 0 :(得分:0)
其getview()
方法行为,每次用户滚动视图时都会创建新视图。在我的博客上查看我的帖子简单替换toggle button with checkbok
并执行它。