NumberPicker Restrictions on non-SDK interfaces

53 views Asked by At

I'm trying to create a custom NumberPicker like this.

Class<?> numberPickerClass = null;
        try {
            numberPickerClass = Class.forName("android.widget.NumberPicker");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Field selectionDivider = null;
        try {
            if (numberPickerClass != null) {
                selectionDivider = numberPickerClass.getDeclaredField("mSelectionDivider");
            }
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }

        if (selectionDivider == null) {
            return;
        }

        try {
            selectionDivider.setAccessible(true);
            selectionDivider.set(this, null);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (Resources.NotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

However, starting from API29, Android is restricting access on non-SDK interfaces. They are suggesting using set/getDividerHeight instead. But I'm super new to Android and I'm not sure how to update my code. Can anyone kindly help? Thanks!

0

There are 0 answers