mercredi 1 juin 2016

How to select all when i check mark All CheckBox?

When check All then below all check select and uncheck then uncheck all, here is List View All is also part of list view its position 0 in map list...

public class MultiSelectBaseAdapter extends BaseAdapter{

Context context;
LayoutInflater inflater;
List<Boolean> selectedList;
Map<Integer, MultipleSelect> mapList;

public MultiSelectBaseAdapter(Context context, Map<Integer, MultipleSelect> mapList) {
    this.context = context;
    this.mapList = mapList;
    selectedList = new ArrayList<>();
    for(int i=0 ; i< mapList.size() ; i++){
        selectedList.add(i, mapList.get(i).isSelected());
    }

    this.inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public List<Boolean> getSelected(){
    return selectedList;
}

public Map<Integer, MultipleSelect> getMapList(){
    return mapList;
}

@Override
public int getCount() {
    if(mapList != null){
        return mapList.size();
    }
    return 0;
}

@Override
public Object getItem(int position) {
    return mapList.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.multiselect_item_layout, parent, false);
        holder = new ViewHolder();
        holder.textView = (TextView) convertView.findViewById(R.id.textview_multiselect);
        holder.checkBox = (CheckBox) convertView.findViewById(R.id.checkbox_multiselect);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.checkBox.setTag(position);

    holder.textView.setText(mapList.get(position).getKeyValueType().getName());

    if(selectedList.get(position)){
        holder.checkBox.setChecked(true);
    } else{
        holder.checkBox.setChecked(false);
    }

    holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            int index = (Integer)buttonView.getTag();
            if(isChecked){
                selectedList.set(index, true);
            }else{
                selectedList.set(index, false);
            }
            notifyDataSetChanged();
        }
    });
    return convertView;
}

public static class ViewHolder {
    TextView textView;
    CheckBox checkBox;
}

}

plz help me i am new in android, i didn't work still on check box this image shows how is looking my list view




Aucun commentaire:

Enregistrer un commentaire