嘿伙计我一直在用动态列表实现numpicker,即在某些事件上有所改变,比如它可能是一个按钮点击或者其他.问题是每当我将列表从较长的长度切换到较小的长度时它起作用,较小的长度到较大的长度它不会改变,而我总是将第一个项目设置为所选项目.它崩溃了.PLS.帮助.我是Android的新手.
码:
public class MainActivity extends Activity {
NumberPicker numPicker = null;
String values1[] = null;
String values2[] = null;
String values3[] = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
values1 =new String []{
"Yello",
"Red",
"White",
"Green",
"Black"
};
values2 =new String []{
"Mango",
"Orange"
};
values3 =new String []{
"Class",
"Pointer",
"Function",
"Interafce",
"Constructor"
};
numPicker = (NumberPicker)findViewById(R.id.numberPicker1);
numPicker.setDisplayedValues(values1);
if(values1.length>1)
{
numPicker.setMaxValue(values1.length-1);
}
else
{
numPicker.setMaxValue(values1.length);
}
numPicker.setMinValue(0);
numPicker.setValue(0);
numPicker.setBackgroundColor(1);
numPicker.setWrapSelectorWheel(false);
numPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
//On value change listner …Run Code Online (Sandbox Code Playgroud) android ×1