Move Seekbar Not Smooth
Solution 1:
you can perform your background task using AsyncTask like this,
seekProgress.setOnSeekBarChangeListener(newSeekBar.OnSeekBarChangeListener() {
@OverridepublicvoidonProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
newgetData().execute(progress);
}
@OverridepublicvoidonStartTrackingTouch(SeekBar seekBar) {
}
@OverridepublicvoidonStopTrackingTouch(SeekBar seekBar) {
}
});
now, you have to define getData() to perform and pass the arguments whichever you required. in you case, we have to pass the progress,
privateclassgetDataextendsAsyncTask<String, Void, String> {
@OverrideprotectedvoidonPreExecute() {
super.onPreExecute();
}
@OverrideprotectedStringdoInBackground(String... progress) {
// perform operation you want with String "progress"String value = "hello" + progress;
return value;
}
@OverrideprotectedvoidonPostExecute(String progressResult) {
// do whatever you want in this thread like// textview.setText(progressResult)super.onPostExecute(progressResult);
}
}
so, PreExecute method will be executed before performing any task in background, then your doInBackground method will be called and you will get arguments pass in this method after doInBackground onPostExecute method will be called which will receive the result returned from the doInBackground method. I hope you get it.
Solution 2:
Don't do it on the UI thread. Make a background thread instead, and handle the callback. Then update your UI on the UI thread if needed.
new AsyncTask<Void, Void, Void>() {
@OverrideprotectedVoid doInBackground(Void... params) {
// your async actionreturnnull;
}
@Overrideprotected void onPostExecute(Void aVoid) {
// update the UI (this is executed on UI thread)super.onPostExecute(aVoid);
}
}.execute();
Solution 3:
If it is suited,move your calculation code in onStopTrackingTouch()
method. This way it will only be called once when you stop sliding on the seekbar.
Post a Comment for "Move Seekbar Not Smooth"