我动态生成少量Numberpicker并将不同整数设置为ID。
现在,当我试图让变更时,它正在崩溃。我设置最大值20和最小值0.当按下键盘的完成按钮时,应用程序崩溃。
请建议我一个正确的方法。我正在尝试的代码如下:
NumberPicker numpick = new NumberPicker(this);
numpick.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
numpick.setMaxValue(20);
numpick.setMinimumWidth(0);
numpick.setId(2);
numpick.setWrapSelectorWheel(true);
numpick.setOnValueChangedListener(new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker numPicker, int newVal, int oldVal) {
// TODO Auto-generated method stub
TextView numberView = (TextView)findViewById(2);
String New = "New Value : ";
numberView.setText(New.concat(String.valueOf(newVal)));
}
});
分享我的LogCat:
12-26 13:09:45.181: E/AndroidRuntime(21551): FATAL EXCEPTION: main
12-26 13:09:45.181: E/AndroidRuntime(21551): java.lang.ClassCastException: android.widget.NumberPicker cannot be cast to android.widget.TextView
12-26 13:09:45.181: E/AndroidRuntime(21551): at com.example.cameraapplication.ImagePickActivity$3.onValueChange(ImagePickActivity.java:187)
12-26 13:09:45.181: E/AndroidRuntime(21551): at android.widget.NumberPicker.notifyChange(NumberPicker.java:1912)
12-26 13:09:45.181:E / AndroidRuntime(21551):在android.widget.NumberPicker.setValueInternal(NumberPicker.java:1697) 12-26 13:09:45.181:E / AndroidRuntime(21551):在android.widget.NumberPicker.validateInputTextView(NumberPicker.java:1877)