我有三个NumberPickers
,我想检测它们的值何时发生变化。我目前将它们用于其他用途,所以我知道它们有效。当您切换 Id 时,我尝试像 onClickListener 一样执行此操作,但 id 在这里不起作用
public class ..... implements OnValueChangeListener {
// Removed
NumberPicker np1;
// Get the id from xml
np1.setOnValueChangedListener(this);
NumberPicker np2;
// Get the id from xml
np2.setOnValueChangedListener(this);
NumberPicker np3;
// Get the id from xml
np3.setOnValueChangedListener(this);
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
// TODO Auto-generated method stub
Log.i("value changed", "true"); // This IS shown
switch (getView().getId()) { // I think this is wrong
case R.id.numberPicker1:
Log.i("value 1", "true"); // Not shown
break;
case R.id.numberPicker2s:
Log.i("value 2", "true"); // Not shown
break;
case R.id.numberPicker3:
Log.i("value 3", "true"); // Not shown
break;
}
}
}
我可以单独添加每个听众,但我认为那会很混乱。