Android- Save checkbox state in listview

前端 未结 2 1604
独厮守ぢ
独厮守ぢ 2021-01-16 16:23

i have listview with checkboxes and \"save\" button.
Whichever checkboxes i check and click save button, i want to save the data related to those checked rows into datab

2条回答
  •  无人及你
    2021-01-16 16:44

    public View getView(final int position, View convertView,ViewGroup paramViewGroup)
    {
        final ViewHolder holder;
        LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
        if (convertView == null) 
        {
            convertView=inflater.inflate(R.layout.addressbook, null);holder = new ViewHolder();
            holder.affffdress_name=(TextView)convertView.findViewById(R.id.addressbook_name);
            holder.affffdress_number=(TextView)convertView.findViewById(R.id.address_number);
            holder.affffdress_name.setText(affffdressbook_name.get(position).toString().trim())
            holder.affffdress_number.setText(addressbook_number.get(position).toString().trim());
            holder.addressbook_check=(CheckBox)convertView.findViewById(R.id.address_check);convertView.setTag(holder); 
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }
    
        holder.addressbook_check.setId(position);
    
        holder.addressbook_check.setOnClickListener(new OnClickListener()
            {
                public void onClick(View v) 
                {
                    CheckBox cb = (CheckBox) v;
                    int id = cb.getId();
                    if (thumbnailsselection[id])
                    {
                        cb.setChecked(false);
                        thumbnailsselection[id] = false;
                    }
                    else
                    {
                        cb.setChecked(true);
                        thumbnailsselection[id] = true;
                    }
                }
            });
    
        holder.addressbook_check.setChecked(thumbnailsselection[position]);
        return convertView;
    }
    
    class ViewHolder
    {  
        TextView affffdress_name;
        TextView affffdress_number;
        CheckBox addressbook_check;
    }
    

提交回复
热议问题