user5418227
user5418227

Reputation:

Hide Date and Year from DatePickerDialog

I have DatePickerDialog, I want to hide Year and Date fields from Dialog, Is this possible to hide specific field? If it is possible then How can I hide? Thanks in advance!!!

My Code is like below

case R.id.ll_date:
                    showDialog(999);
                    break;

And Dialog is

@Override
    protected Dialog onCreateDialog(int id) {
        if (id == 999) {
            DatePickerDialog datePickerDialog = new DatePickerDialog(mActivity, myDateListener, currYear, currMonth, currDay);
            return new DatePickerDialog(this, myDateListener, currYear, currMonth, currDay);
        }
        return null;
    }

        private DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker arg0, int year, int month, int day) {
            Calendar selectedCal = Calendar.getInstance();
            selectedCal.set(year, month, day);
            DateFormat df = new SimpleDateFormat("MM/dd/yyyy", new Locale("en_US"));
            String date = df.format(new Date());
            String selectedDate = df.format(selectedCal.getTime());
            try {
                Date current = df.parse(date);
                Date selected = df.parse(selectedDate);
                Log.print("Date =================== " + day);
                if (selected.before(current)) {
                    showSnackbar(txtDate, getString(R.string.alert_can_not_able_previous_date));
                } else {
                    int month1 = month + 1;
                    String Date = (month1 < 10 ? ("0" + month1) : (month1)) + "/" + (day < 10 ? ("0" + day) : (day)) + "/" + year;
                    txtDate.setText(Date);
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    };

Upvotes: 0

Views: 1634

Answers (1)

Mohammed Sameer Ahmad
Mohammed Sameer Ahmad

Reputation: 437

this works for you: this is for year hiding

datePickerDialogObject.findViewById(Resources.getSystem().getIdentifier("year", "id", "android")).setVisibility(View.GONE);

and this is for hiding date from datepicker

datePickerDialogObject.findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).setVisibility(View.GONE);

Upvotes: 1

Related Questions