Android的搜索栏setOnSeekBarChangeListenerAndroid、setOnSeekBarChangeListener

2023-09-05 01:26:13 作者:爱如指间沙

我想了解一下Android的SeekBars OnSeekBarChangeListener的行为。它是正确的,该onProgressChanged法只是获取上的SeekBar第一触摸和在搜索栏的最后一抹通知?

I'm wondering about the behavior of the android SeekBars OnSeekBarChangeListener. Is it correct, that the onProgressChanged-method just gets notified for the first touch on the seekbar and on the last touch on the seekbar?

我试图刷新一个TextView,应该显示搜索栏的当前进度。但是TextView的是刚刚更新的第一次接触和最后的接触。调试这证实了我的假设,该方法就被称为两次:(我想有是TextView的显示在搜索栏每一个进步的改变。

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, the method is just called 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 possiblity to get a progress listener that is called for every litte progress change.

感谢您对我的帮助!

推荐答案

我希望这将帮助你:

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

    }       
});