Search code examples
androidfirebasefirebase-realtime-databaseandroid-datepickerdatepickerdialog

Datepickerdialog don't open when its empty


In the app the fields are not open by click when its empty. Its possible if the field is already filled for intance with 23-03-2017. The code give no error. Tested on different API levels. Who can help me?

                break;
            case InstrumentItem.S_FREEDATE:
            case InstrumentItem.S_BUYDATE:
            case InstrumentItem.S_CERTDATE:
            case InstrumentItem.S_EXPDATE:
                holder.valueLabel.setFocusable(false);
                holder.valueLabel.setOnClickListener(view ->  {
                    try {
                        showDatePickerDialog(holder.valueLabel.getText().toString(), (datePicker, year, month, day) -> {
                            String dateInFormat = getDateInFormat(year, month, day);
                            holder.valueLabel.setText(dateInFormat);
                            mItems.get(position).value = dateInFormat;

                        }).show();
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                });
                break;

Solution

  • The reason why it was not working, there was no date. I fixed it with the option to pick the device date (current date), the DatePickerdialog opens.

                            try {
                                String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
                                holder.valueLabel.setText(date);
                                mItems.get(position).value = date;