android - Seekbar not updating TextView in listview item -


i have listview array adapter, shows different views represent different properties of item. same item added list multiple times, create views.

since views unique, created enum manage each view's inflation.

the problem is, maxdistancetv's text not updated when setmaxdistancetext() called onprogresschanged(seekbar seekbar, int progress, boolean fromuser).

i tried using new handler().post(new runnable()...), runonuithread(new runnable()...), .invalidate(), .postinvalidate() , none of them worked.

when debugging, can see maxdistancetv's text(mtext) updating new correct value, change not reflected in ui.

the following relevant part of enum:

public enum bledeviceproperties implements idevicepropertiesinflater {      alert_distance(r.layout.property_alert_distance, new idevicepropertiesinflater() {          private textview maxdistancetv;         private seekbar maxdistancesb;         private bledeviceinfo info;         private view view;          private void setmaxdistancetext(){             maxdistancetv = (textview) view.findviewbyid(r.id.max_distance_tv);             maxdistancetv.settext(string.valueof(info.getthreshold()));         }          private void setmaxdistanceprogress(){             maxdistancesb = (seekbar) view.findviewbyid(r.id.max_distance_sb);             maxdistancesb.setmax(bledeviceinfo.steps);             maxdistancesb.setprogress(info.getthresholdnormalized());             maxdistancesb.setonseekbarchangelistener(new seekbar.onseekbarchangelistener() {                 @override                 public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) {                     info.setthresholdnormailized(progress);                     bluetoothleservicemessanger.getinstance().sendnewrssithresholdset(info.getthreshold());                     setmaxdistancetext();                 }                  @override                 public void onstarttrackingtouch(seekbar seekbar) {                  }                  @override                 public void onstoptrackingtouch(seekbar seekbar) {                 }             });         }          @override         public void inflatedata(view view, bledeviceinfo info) {             this.info = info;             this.view = view;             setmaxdistancetext();             setmaxdistanceprogress();         }     }),     ...     private int viewid;     private idevicepropertiesinflater propertiesinflater;      @override     public void inflatedata(view view, bledeviceinfo info) {         if(propertiesinflater != null){             propertiesinflater.inflatedata(view,info);         }     }      public int getviewid() {          return viewid;     }      bledeviceproperties(int viewid, idevicepropertiesinflater propertiesinflater) {         this.viewid = viewid;         this.propertiesinflater = propertiesinflater;     } } 

idevicepropertiesinflater

public interface idevicepropertiesinflater {     void inflatedata(view view,bledeviceinfo info); } 

devicepropertiesadapter

public class devicepropertiesadapter extends arrayadapter<bledeviceinfo>{      private static final int view_type_count = 4;      private activity activity;      public void setinfo(bledeviceinfo info){         clear();         for(int i=0;i<view_type_count;i++){             add(info);         }         notifydatasetchanged();     }      @override     public int getitemviewtype(int position) {         return position;     }      @override     public int getviewtypecount() {         return view_type_count;     }      public devicepropertiesadapter(activity activity, int resource) {         super(activity, resource);         this.activity = activity;     }      @override     public view getview(int position, view view, final viewgroup parent) {         view rowview;         if(view == null) {             layoutinflater inflater = activity.getlayoutinflater();             rowview = inflater.inflate(bledeviceproperties.values()[position].getviewid(), null);         }else{             rowview = view;         }          bledeviceproperties.values()[position].inflatedata(rowview, getitem(position));          return rowview;     }  } 

eventually, instead of calling setmaxdistancetext() onprogresschanged, tried:

@override public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) {     info.setthresholdnormailized(progress);     bluetoothleservicemessanger.getinstance().sendnewrssithresholdset(info.getthreshold());     //setmaxdistancetext();     maxdistancetv = (textview) ((viewgroup)seekbar.getparent()).findviewbyid(r.id.max_distance_tv);     maxdistancetv.settext(string.valueof(info.getthreshold())); } 

and worked. still don't know why textview not update using code in original question.

edit: read here:

never set layout_height , layout_width of listview wrap_content getview() force adapter child measuring height of views drawn in list view , can cause unexpected behaviour returning convertview list not scrolled.always use match_parent or fixed width/height.

the original code worked after changing values of layout_height , layout_width match_parent.


Comments