Rumaan Rumaan - 1 year ago 87
Android Question

Setting timer with seek bar

I have an app in which I have used minutes and seconds as a textview that changes with the dragging of seek bar and it is working fine. My only problem is that when it reaches to 10 minutes (I have set max to 600 which is ten minutes) it should be shown like this e.g 10:00 but unfortunately it is shown in like this 10:0
I have tested it in both emulator and genymotion below is my code

SeekBar seekBar = (SeekBar)findViewById(;
final TextView timerTextView = (TextView)findViewById(;

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {

int minutes = progress / 60;
int seconds = progress - minutes * 60;

String secondString = Integer.toString(seconds);

if (secondString == "0") {

secondString = "00";

timerTextView.setText(Integer.toString(minutes) + ":" + secondString);


Answer Source

Why don't you use

if (seconds == 0) {
    secondString = "00";

String comparison might have some issue!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download