[ACCEPTED]-How to display date picker for android with only month and year fields?-datepicker
I just have released a new date picker framework 7 which allows you to create custom date picker. I 6 also provided some example date pickers 5 like the one you are looking for. Hope, that 4 it works for you.
the code can be found here: https://github.com/bendemboski/DateSlider
UPDATE 06/2014: This 3 library was developed 2010 and has been 2 unmaintained since 2011. So it is most likely 1 out of date by now.
It possible to hack the DatePicker instance 3 using reflection. This way, you are able 2 to access the NumberPicker instance which 1 represent the day in the DatePicker:
datePicker = (DatePicker) findViewById(R.id.expiration_date);
try {
Field f[] = datePicker.getClass().getDeclaredFields();
for (Field field : f) {
if (field.getName().equals("mDayPicker")) {
field.setAccessible(true);
Object dayPicker = new Object();
dayPicker = field.get(datePicker);
((View) dayPicker).setVisibility(View.GONE);
}
}
} catch (SecurityException e) {
Log.d("ERROR", e.getMessage());
}
catch (IllegalArgumentException e) {
Log.d("ERROR", e.getMessage());
} catch (IllegalAccessException e) {
Log.d("ERROR", e.getMessage());
}
Speaking of reflection this works in Android 1 4.4.2 SDK
"mDaySpinner"
instead
"mDayPicker"
I think It's the best solution
datePicker.findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).setVisibility(View.GONE);
0
EDIT: as per the comment below, I wouldn't 7 follow this answer anymore.
I don't think 6 you can do that with the default date picker. You'll 5 have to create it out of basic Android UI 4 elements. But instead of going to that 3 trouble, why not use a better library element 2 like this great-looking iPhone-esque wheel: http://code.google.com/p/android-wheel/ I 1 haven't used it yet, but I plan to!
This works fine in 2.2 version. But title 1 of the dialog is not changed.
for (Field datePickerDialogField : datePickerDialogFields) {
if (datePickerDialogField.getName().equals("mDatePicker")) {
datePickerDialogField.setAccessible(true);
DatePicker datePicker = (DatePicker) datePickerDialogField.get(datePickerDialog);
Field datePickerFields[] = datePickerDialogField.getType().getDeclaredFields();
for (Field datePickerField : datePickerFields) {
if ("mDayPicker".equals(datePickerField.getName())) {
datePickerField.setAccessible(true);
Object dayPicker = new Object();
dayPicker = datePickerField.get(datePicker);
((View) dayPicker).setVisibility(View.GONE);
}
}
}
}
You can use the https://github.com/SimonVT/android-datepicker widget for backported compatibility 1 and make the day picker 'gone'
<net.simonvt.numberpicker.NumberPicker
android:id="@+id/day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dip"
android:layout_marginRight="16dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone"
/>
For Hiding Day :
datePicker.findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).setVisibility(View.GONE);
&
For hiding Month :
datePicker.findViewById(Resources.getSystem().getIdentifier("month", "id", "android")).setVisibility(View.GONE);
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.