Limitations on Android NumberPicker on Gingerbread

I have a numberpicker:

AlertDialog alertDialog = builder.create(); alertDialog.setTitle("Quantidade"); NumberPicker NP = (NumberPicker)view.findViewById(R.id.npicker); NP.setMaxValue(1000); NP.setMinValue(1); alertDialog.setButton(...); alertDialog.show(); 

This works fine on Android 4.0.x, but on Android 2.3.x I get

 java.lang.NoSuchMethodError: android.widget.NumberPicker.setMaxValue 

If I remove NP.setMaxValue(1000) and NP.setMinValue(1) , it works, but the restrictions are set to 0, is there a way to set number selection limits on Android 2.3.x?

0
source share
2 answers

According to the documentation, NumberPicker (and all of its methods) are only available from API level 11 (SDK 3.0). Therefore, if you need compatibility with 2.3.x, you need to have your own implementation. Fortunately, here already exists here

Edit

The Internet was not very affectionate at the link above, and it is no longer available. Even the alternatives suggested in the comments have also disappeared. You better write your own.

+2
source

If you are viewing the source code of the AOSP Messaging app on Github under the gingerbread branches, there is a NumPicker, written by Romain Guy, which should allow you to provide NumberPicker with at least gingerbread.

If you copy the source code into your project, I would recommend dynamically choosing between this custom instance of NumberPicker and the frameworks instance based on the SDK version to use all the new features and design based on the current API level.

Here is the link to the source code: https://github.com/android/platform_packages_apps_mms/blob/gingerbread-release/src/com/android/mms/ui/NumberPicker.java

I would recommend looking into the project for information on how to use it.

0
source

All Articles