0
나는 NumberPickers
세 개가 있는데 값이 모두 변경되면이를 감지하고 싶습니다. 나는 현재 그들이 다른 어떤 것을 위해 사용하기 때문에 그들이 일한다는 것을 알고있다. 난 당신이 이드 전환 OnClickListener를처럼하려고 노력하지만, ID가 나는 각 리스너 separatley를 추가 할 수 있지만 그 지저분하다고 생각 여기여러 OnValueChangedListeners
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;
}
}
}
작동하지 않습니다.
좋아, 내가 볼 :
죄송합니다. 나는 질문을 편집했다 – RiThBo
@RiThBo Ooops 내가 본다 :-D 나는 내 대답을 업데이트했다 – tiguchi
고마워! switch (picker.getId()) 만 필요했고 완벽하게 작동합니다. :-) – RiThBo