Android SeekBar setOnSeekBarChangeListener

user1162729 picture user1162729 · Jan 21, 2012 · Viewed 124.3k times · Source

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.

Answer

Balaji Gunasekar picture Balaji Gunasekar · Jul 24, 2012

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();

    }       
});