我在Android应用中有几个SeekBar
实际上做同样的事情(设置低音,高音,音量)。为了保存每个OnSeekBarChangeListener
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
?或者有更清洁或更好的方法吗?
答案 0 :(得分: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;
}
}