I am developing an application based on Android 2.1, on one page of my application, there needs an numberpicker. we know that android 2.1 doesn’t contain numberpicker control, so I write one.
I need to show my version of numberpicker on Android 2.1, but the ICS style numberpicker in Android 4.0, to achieve that aim, I used reflection, When in my code, I detected the current Build.VERSION.SDK_INT >= 14, I reflect a numberpicker of the target platform, and add it to current view dynamically.
My question is I can reflect a numberpicker when I run my application on an Android 4.0 platform, but the numberpicker style doesnot appear to be ICS style, Why?
thanks in advance!
If you have the patience you could probably back-port the NumberPicker class. That aside, why use reflection? If you set your target API to 15 this is all you need. In your
layoutfolder declare your alternative number picker. Inlayout-v11(NumberPickeris available in API 11 Honeycomb or higher) declareandroid.widget.NumberPicker. Give each the same ID and in your Activity have something along these lines:This was you do not need reflection and will not run into any crashes due to accessing non-existent APIs. From here on out you just check
if (mNumPicker == null)andif (mOldNumPicker == null)and determine which methods to call based on that. There is also this example of a Number Picker using Buttons and an EditText.