using List view with check box. after click on check box and doing scroll, check box state is not working properly.
i tried check box in listview not working properly
but it is not working for me.
here is my Adapter code:
private class CustomerEventsAdapter extends BaseAdapter {
private Context myContext;
private ArrayList<Events> myEventArrayList;
private LayoutInflater mInflater;
private Boolean isSelected = false;
public EventsAdapter(Context ctx, ArrayList<Events> theArrayListEvents) {
this.myContext = ctx;
this.myEventArrayList = theArrayListEvents;
mInflater = LayoutInflater.from(ctx);
}
@Override
public int getCount() {
return myEventArrayList.size();
}
@Override
public Object getItem(int i) {
return myEventArrayList.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(final int i, View convertView, ViewGroup viewGroup) {
View view = convertView;
if (view == null) {
view = mInflater.inflate(R.layout.event_item_list, null);
final ViewHolder holder = new ViewHolder();
holder.myCheckBoxCustomerEventItem = (CheckBox) view.findViewById(R.id.checkBoxCustomerEventItem);
holder.myCheckBoxCustomerEventItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Events events = myEventArrayList.get(i);
//is chkIos checked?
if (((CheckBox) v).isChecked()) {
holder.myCheckBoxCustomerEventItem.setChecked(true);
eventsInfo.setMyIsSelected(true);
} else {
holder.myCheckBoxCustomerEventItem.setChecked(false);
eventsInfo.setMyIsSelected(false);
}
//case 2
}
});
view.setTag(holder);
}
if (view != null) {
ViewHolder holder = (ViewHolder) view.getTag();
Events eventsInfo = myEventArrayList.get(i);
boolean isChecked = eventsInfo.getMyIsSelected();
if (isChecked) {
holder.myCheckBoxCustomerEventItem.setChecked(true);
} else {
holder.myCheckBoxCustomerEventItem.setChecked(false);
}
}
return view;
}
}
Aucun commentaire:
Enregistrer un commentaire