android - How to enable and disable switchCompat accrodingly to database status? -


i have app in have listview data stored in sqlite database. listview contain switchcompat when enable switch @ index of listview setting status "0" , when disable item setting "1". when status set "0" enable swicth , when status set toi "1" disable switch. pls help.

code:-

  listviewholder.switchcompat.setoncheckedchangelistener(null);     boolean ischeck;     ischeck = !liststorage.get(position).getstatus().equalsignorecase("0");      listviewholder.switchcompat.setchecked(ischeck);      listviewholder.switchcompat.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {         @override         public void oncheckedchanged(final compoundbutton buttonview, final boolean ischecked) {             if (ischecked) {                 new alertdialog.builder(mcontext, r.style.appcompatalertdialogstyle).settitle("warning").setmessage("you want whitelist application?").setpositivebutton("yes", new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialog, int pos) {                         //adding items in dataset                         cblacklistmodel applist = liststorage.get(position);                         string appname = applist.getname();                         string apppackage = applist.getpackname();                         byte[] appicon = applist.getimage();                         string appstatus = "1";                          applistdatabase.updateapp(appname,apppackage,appicon,appstatus);                          notifydatasetchanged();                         listviewholder.switchcompat.setchecked(ischecked);                      }                 }).setnegativebutton("no", new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialog, int which) {                         notifydatasetchanged();                         listviewholder.switchcompat.setchecked(ischecked);                     }                 }).show();              } else {                 cblacklistmodel model = liststorage.get(position);                 string appname = model.getname();                 string apppackage = model.getpackname();                 byte[] appicon = model.getimage();                 string appstatus = "1";                  applistdatabase.updateapp(appname,apppackage,appicon,appstatus);                 notifydatasetchanged();                 listviewholder.switchcompat.setchecked(false);                  toast.maketext(mcontext, "removed", toast.length_long).show();              }         }       }); 

if(ischeck.equals("0")){

listviewholder.switchcompat.setchecked(true); }

in adition it...setchecked false default in xml.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -