Android SeekBar setOnSeekBarChangeListener

前端 未结 5 714
借酒劲吻你
借酒劲吻你 2020-12-03 09:58

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 to

5条回答
  •  青春惊慌失措
    2020-12-03 10:11

    onProgressChanged() should be called on every progress changed, not just on first and last touch (that why you have onStartTrackingTouch() and onStopTrackingTouch() methods).

    Make sure that your SeekBar have more than 1 value, that is to say your MAX>=3.

    In your onCreate:

     yourSeekBar=(SeekBar) findViewById(R.id.yourSeekBar);
     yourSeekBar.setOnSeekBarChangeListener(new yourListener());
    

    Your listener:

    private class yourListener implements SeekBar.OnSeekBarChangeListener {
    
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                                // Log the progress
                Log.d("DEBUG", "Progress is: "+progress);
                                //set textView's text
                yourTextView.setText(""+progress);
            }
    
            public void onStartTrackingTouch(SeekBar seekBar) {}
    
            public void onStopTrackingTouch(SeekBar seekBar) {}
    
        }
    

    Please share some code and the Log results for furter help.

提交回复
热议问题