java - How to fire onProgressChanged () per segment -
i working on android application , facing optimization problem : have seekbar
whenever user drags thumb near middle (the max value
100 near middle mean between 55 , 45 ) thumb should automatically jump middle .
@override public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { x=seek.getprogress(); if (x>45 && x<55) {seek.setprogress(50);} socket.emit("move1", x); }
it works whenever thumb jumps onprogresschanged
event keeps firing continuously until user moves thumb away middle area , consumes resources . want while progress of seekbar between 45 , 55 onprogresschanged
fires once.
this may - fromuser
parameter tells whether progress changed due action user or programmatically. if changed user, , if not @ 50, set 50.
seekbar.setonseekbarchangelistener(new seekbar.onseekbarchangelistener() { @override public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { int x = seekbar.getprogress(); if(fromuser && x != 50 && x > 45 && x < 55) { seekbar.setprogress(50); } .... } });
Comments
Post a Comment