Android: SeekBar onProgressChanged-event doesn't get fired when setting progress programmatically -


my onprogresschanged()-event doesn't fired when set progress of seekbar programmatically, fired fine when physically move seekbar slider.

i'd expect event fire when using setprogress() - android developer reference states that:

public abstract void onprogresschanged (seekbar seekbar, int progress, boolean fromuser)

notification progress level has changed. clients can use fromuser parameter distinguish user-initiated changes occurred programmatically.

some code snippets project:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.my_activity);                     final seekbar myseekbar = ((seekbar) findviewbyid(r.id.myseekbar));      myseekbar.setonseekbarchangelistener(new onseekbarchangelistener(){         @override         public void onprogresschanged(seekbar arg0, int arg1, boolean arg2) {             // stuff         }     } }   @override protected void onresume() {     super.onresume();      final seekbar myseekbar = ((seekbar) findviewbyid(r.id.myseekbar));     myseekbar.setprogress(somevalue); // should trigger onprogresschanged(), doesn't... } 

+1 romuald brunet's answer:

here "hack" fix it:

        <seekbar android:id="@+id/seekbar"              android:layout_width="match_parent"              android:layout_height="wrap_content"               android:progress="1"             android:max="200" /> 

note progress="1", set default progress in layout 1, in code when default 0, change in progress occurs , onprogresschanged() event fires.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -