1

SeekBar在一个 Android 应用程序中有几个 s,它们几乎做同样的事情(设置低音、高音、音量)。为了节省为OnSeekBarChangeListenerper输入新的本地类SeekBar,我尝试创建一个类,该类onStopTrackingTouch将确定哪个小部件正在调用它,并执行正确的操作。

public class mySeekBar implements SeekBar.OnSeekBarChangeListener {
    int progressChanged = 0;

    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
        progressChanged = progress;
    }

    public void onStartTrackingTouch(SeekBar seekBar) {}

    public void onStopTrackingTouch(SeekBar seekBar) {
          // i want a case statement here switched on the widget ID/name, so 
          // i can set the appropriate string s (bass, treble, volume)
        String s = "set_treble " + progressChanged;
        client.sendMessage(s);
    }

}

如何确定哪个小部件正在调用onStopTrackingTouch?或者有更清洁或更好的方法吗?

4

1 回答 1

1

100% 你可以这样确定;

public void onStopTrackingTouch(SeekBar seekBar) {
          // i want a case statement here switched on the widget ID/name, so 
          // i can set the appropriate string s (bass, treble, volume)
        String s = "set_treble " + progressChanged;
        client.sendMessage(s);

       switch (seekBar.getId()) {
                case R.id.seekVolume:

                    break;
                case R.id.bass:
                    break;
                case R.id.trouble:
                    break;
                default:
                    break;
                }
    }
于 2013-08-24T06:17:37.177 回答