How to update textviews when seekbar is dragged

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to update textviews when seekbar is dragged



Here you can see what im trying to achieve



https://imgur.com/a/zEpWI



The first gif is what i have now, and the second on is what i want to get.



The code works but the textview which displays song current position is only updating when i stop dragging, but i want it to update when im dragging it.



Check out the gifs i posted in the link so you understand what i want to achieve.



Thanks in advance,



Vince



updateProgressBar(); called when i change a song



My code


private Runnable mUpdateTime = new Runnable() {
@Override
public void run() {
long songCurrentTime = mediaPlayer.getCurrentPosition();
long songTotalTime = mediaPlayer.getDuration();

tvSongCurrentTime.setText(""+utilities.msToTimer(songCurrentTime));
tvSongTotalTime.setText(""+utilities.msToTimer(songTotalTime));

int progress = (int)(utilities.getProgressPercentage(songCurrentTime, songTotalTime));
seekBar.setProgress(progress);

mHandler.postDelayed(this, 100);
}
};

public void updateProgressBar(){
mHandler.postDelayed(mUpdateTime, 100);
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean
fromUser) {

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
mHandler.removeCallbacks(mUpdateTime);
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mHandler.removeCallbacks(mUpdateTime);
int songTotalTime = mediaPlayer.getDuration() ;
int currentPosition = utilities.progressToTimer(seekBar.getProgress(),
songTotalTime);

mediaPlayer.seekTo(currentPosition);
updateProgressBar();
}





use updateProgressBar(); in onProgressChanged also
– Shivam Kumar
2 hours ago





github.com/naman14/Timber check this.
– Hoàng Vũ Anh
2 hours ago




2 Answers
2



You should do it in 'onProgressChanged' method. Like this :


@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean
fromUser) {
if(fromUser)
//myTextView.setText("" + progress);
updateProgressBar();
}



Follow the below code. It may help you.


final TextView sometextview=findViewById(R.id.someid);//your textview
sometextview.setText("Hello Android");

final SeekBar seekbar=(SeekBar) findViewById(R.id.someseekbar); //your seekbar
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { //listener for your seekbar

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub

sometextview.setTextSize(progress+"%");//Here is the textview with the progress number.

}
});






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived