android - ListView with toggle button doesn't scroll smoothly -


i have custom listview. it's populated cursor adapter. it's every row includes 1 imageview, 2 textviews , 1 togglebutton. these loads fine. when change state of group of togglebuttons true, when scroll fast listview not scrolling smoothly hangs sec , scrolls. happens when after group of unchecked buttons appears group of checked buttons , vice versa. why list view hangs while scrolling?

any appreciated. code looks this:

 public void bindview(view view, context context, final cursor cursor) {      final viewholder viewholder = new viewholder(view);          (...)      if (viewholder.toggle_artist != null) {         viewholder.toggle_artist.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {             public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {                 int favourite = ischecked ? 1 : 0;                 contentvalues value = new contentvalues();                 string = amdmcontract.artistentry.table_name + "." +                         amdmcontract.artistentry._id + " = " + tableid;                 value.put(amdmcontract.artistentry.column_favorite, favourite);                 mcontext.getcontentresolver()                         .update(amdmcontract.artistentry.content_uri,                                 value, where, null);             }         });         int favfromdb = cursor.getint(col_favourite);         viewholder.toggle_artist.setchecked(favfromdb == 1);     } } 

can please try below code toggle button checkchangelistener.

reason: in baseadapter getview() method calls on every scroll of listview , calls oncheckchangelistener() automatically.

so replace code below code:

tgl.setonclicklistener(new view.onclicklistener() {       @override       public void onclick(view v) {           togglebutton selectedtoggle = (togglebutton) v;           if(selectedtoggle.ischecked()){                 // code if toggle checked           }else{                 // code if toggle not checked            }         }   }); 

hope you.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -