How to get the current progress on your SeekBar in android?

By | April 24, 2012

I have already shown how to use seekBar in android.
This simple snippet helps you to get the current progress in the seekbar.
It’s same code from this
post, only thing is I added the getProgress method.

package com.coderzheaven;

import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

public class SeekBarDemo extends Activity  implements SeekBar.OnSeekBarChangeListener {
	SeekBar mSeekBar;
    TextView mProgressText;
    TextView mTrackingText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        mSeekBar = (SeekBar)findViewById(R.id.seek);
        int p = mSeekBar.getProgress();
        System.out.println("Current Progress = " + p);
        mSeekBar.setOnSeekBarChangeListener(this);
        mProgressText = (TextView)findViewById(R.id.progress);
        mTrackingText = (TextView)findViewById(R.id.tracking);
    }

    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
        mProgressText.setText(progress + " " +
                getString(R.string.seekbar_from_touch) + "=" + fromTouch);

        System.out.println("onProgressChanged >> Current Progress = " + progress);
    }

    public void onStartTrackingTouch(SeekBar seekBar) {
        mTrackingText.setText(getString(R.string.seekbar_tracking_on));
    }

    public void onStopTrackingTouch(SeekBar seekBar) {
        mTrackingText.setText(getString(R.string.seekbar_tracking_off));
    }
}

Check the Logcat for the current progress or the TextView in which I am showing.
Take the xml from the This post

Please leave your valuable comments.

One thought on “How to get the current progress on your SeekBar in android?

  1. Patrick Mahoney

    Hmm… as soon as I stopped trying to use the getProgress() method, it worked just like I wanted it to. The program was force closing as soon as I touched the thumb, but now my Java class looks like this:

    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
    paycheckPercentView.setText(progress + “%”);

    }

    The Log Cat entry was saying that the problem was where I was using setText.

    Oh well, now that it works I’m happy, and it’s simpler now.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *