Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SeekBar setOnSeekBarChangeListener

I'm wondering about the behavior of the android SeekBars OnSeekBarChangeListener. In particular, is the onProgressChanged-method notified only for the first and the last touch on the seekbar?

I'm trying to refresh a TextView that should show the current progress of the SeekBar. But the TextView is just updated on first touch and last touch. Debugging this confirms my assumption that this method is called just twice :( What I would like to have is that the TextView shows every progress change in the SeekBar.

In short: I am searching for a possibility to get a progress listener that is called for every little progress change.

like image 822
user1162729 Avatar asked Jan 21 '12 20:01

user1162729


People also ask

What is a SeekBar in Android?

android.widget.SeekBar. A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.

How can I get SeekBar value?

The SeekBar class is a subclass of ProgressBar , which contains a getProgress() method. Calling PRICEbar. getProgress() will return the value you are looking for.

How do I SeekBar progress?

You are looking for the method getProgress() of the ProgressBar class as SeekBar is a subclass of ProgressBar . So basically it would be something like that. int value = seekBar. getProgress();


1 Answers

I hope this will help you:

final TextView t1=new TextView(this);  t1.setText("Hello Android");         final SeekBar sk=(SeekBar) findViewById(R.id.seekBar1);      sk.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {             @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                t1.setTextSize(progress);         Toast.makeText(getApplicationContext(), String.valueOf(progress),Toast.LENGTH_LONG).show();      }        });              
like image 147
Balaji Gunasekar Avatar answered Sep 27 '22 02:09

Balaji Gunasekar