I am trying to hide the year field from the date picker widget.This may look like a repeated question but the answers given for previous questions are not helping me to hide the
Try this, it works for me.
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
// hide year from datepicker
DatePickerDialog dlg = new DatePickerDialog(this,
datePickerListener, year, month, day) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int year = getContext().getResources().getIdentifier(
"android:id/year", null, null);
if (year != 0) {
View yearPicker = findViewById(year);
if (yearPicker != null) {
yearPicker.setVisibility(View.GONE);
}
}
}
};
return dlg;
}
return null;
}