On my settings screen I have a date picker widget. In the designer in Eclipse, it shows as I want (3 spinners for D-M-Y) but when I test on my device, I get a rather odd vie
I made it work with the following XML configuration:
android:datePickerMode="spinner"
android:calendarViewShown="false"
Only the following configuration didn't work for me:
android:calendarViewShown="false"
If you are targeting a later version of the API, you can use the following XML (no need to write Java code) in your <DatePicker>
:
android:calendarViewShown="false"
The method in DatePicker
public void setCalendarViewShown (boolean shown)
exists starting with API 11. If you minSdkLevel = 7 the compiler does not recognize this as a valid method - the method does not exist on android 2.3 or 2.2. The best way is to solve this is using reflection. Something like this should work properly:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 11) {
try {
Method m = minDateSelector.getClass().getMethod("setCalendarViewShown", boolean.class);
m.invoke(minDateSelector, false);
}
catch (Exception e) {} // eat exception in our case
}
In those cases I use
import android.os.Build;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void someThing() {
[...]
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
minDateSelector.setCalendarViewShown(false);
}
}
I think the readability is better than using reflection and the style is better than catch and ignore exceptions. Of course the reflection thing is also working.
I had the same problem as you, I couldn't make the change appear via XML.
You are on the right track, try changing your last line to:
minDateSelector.setCalendarViewShown(false);