Saving Toggle Button state in database inside listview
Hello dear Can anyone tell me how to store status of Toggle Button inside a listview into SQLite database.....
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit GuptaRank #190 · 12.8K reputationPosted Jan 1, 2017, 3:36 AM EST
Naeem Khan10 reputationPosted Jan 1, 2017, 4:41 AM EST
public class RoomContactAdapter extends ArrayAdapter { Context context; int layoutResourceId; ArrayList arrayList=new ArrayList(); public RoomContactAdapter(Context context, int layoutResourceId, ArrayList arrayList) { super(context, layoutResourceId, arrayList); this.layoutResourceId = layoutResourceId; this.context = context; this.arrayList = arrayList; } @Override public View getView(final int position, View convertView, final ViewGroup parent) { View row = convertView; ImageHolder holder = null; if(row == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new ImageHolder(); holder.txtTitle = (TextView)row.findViewById(R.id.textviewroomcontact); holder.imgIcon = (ImageView)row.findViewById(R.id.roomcontateimageviewid); holder.textViewItem=(TextView)row.findViewById(R.id.textviewItemid); holder.aSwitch=(Switch) row.findViewById(R.id.SwitchID); holder.textViewstatus=(TextView)row.findViewById(R.id.textviewstatusid); row.setTag(holder); } else { holder = (ImageHolder)row.getTag(); } RoomContact picture = arrayList.get(position); holder.txtTitle.setText(picture ._name); holder.textViewItem.setText(picture._item); holder.textViewstatus.setText(picture._status); //convert byte to bitmap take from contact class byte[] outImage=picture._image; ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage); Bitmap theImage = BitmapFactory.decodeStream(imageStream); holder.imgIcon.setImageBitmap(theImage); holder.aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { ((ListView)parent).performItemClick(compoundButton,position,3); } }); return row; } static class ImageHolder { ImageView imgIcon; TextView txtTitle; TextView textViewItem; TextView textViewstatus; Switch aSwitch; } }