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 Comment

  1. Patrick Mahoney August 12, 2011 at 7:26 am

    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.

     

Leave a Reply

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

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.