我需要创建两个NumberPicker,一个包含5000个元素,另一个包含20000个元素。 我在我的应用程序启动时设置了这两个选择器(在启动画面活动中),但是生成需要很多时间(或多或少10/15秒)。 有哪种方法可以优化此过程并缩短生成时间?
这是我如何初始化拣货员:
picker = new NumberPicker(context);
picker.setLayoutParams(
new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
pickerValues = new String[20000];
for (int i = 0; i < pickerValues.length; i++)
pickerValues[i] = i;
picker.setMinValue(1);
picker.setMaxValue(20000);
picker.setWrapSelectorWheel(false);
picker.setDisplayedValues(pickerValues);
picker.setValue(1);
picker.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
然后我改变了选择器的颜色(它显示在自定义对话框中)
final int count = picker.getChildCount();
for (int i = 0; i < count; i++) {
View child = picker.getChildAt(i);
if (child instanceof EditText) {
try {
Field selectorWheelPaintField = picker.getClass()
.getDeclaredField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
((Paint) selectorWheelPaintField.get(picker))
.setColor(MyApp.getContext().getResources().getColor(R.color.blue));
((EditText) child).setTextColor(MyApp.getContext().getResources().getColor(R.color.blue));
picker.invalidate();
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
}
}
}