How to hide/remove date field in datepickerdialog. Actually my requirement is to use the native date picker dialog but it shows up with day, month, and year. But as per my r
private Calendar mCalendar;
mCalendar = Calendar.getInstance();// Initialize Calendar
dialog_date_picker.xml
DialogMethod called on Click:
private void ExpiryDialog() {
System.out.println("Inside Dialog Box");
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_date_picker);
dialog.show();
final DatePicker datePicker = (DatePicker) dialog.findViewById(R.id.date_picker);
date_time_set = (Button) dialog.findViewById(R.id.date_time_set);
datePicker.init(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), null);
LinearLayout ll = (LinearLayout) datePicker.getChildAt(0);
LinearLayout ll2 = (LinearLayout) ll.getChildAt(0);
ll2.getChildAt(1).setVisibility(View.INVISIBLE);
date_time_set.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view){
dialog.dismiss();
Integer month = datePicker.getMonth()+1;
Integer year = datePicker.getYear();
expMonth = (month.toString().length() == 1 ? "0"+month.toString():month.toString());
expYear = year.toString();
etExpiryDate.setText(expMonth + "/" + expYear);
}
});
}
This code works and hides the day in a DatePicker, so I can show Expiry Date for Cards. Enjoy!!