1

1 つは 5000 要素、もう 1 つは 20000 要素の 2 つの NumberPicker を作成する必要があります。アプリの起動時 (スプラッシュスクリーン アクティビティ内) にこの 2 つのピッカーを設定しましたが、生成には多くの時間がかかります (多かれ少なかれ 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) {

                }
            }
        }
4

0 に答える 0