1

When I click edittext, date picker dialog opens. without clicking done button in date picker and clicked outside of dialog, it sets in edittext.

I checked this but this works for first time. When selecting second time by choosing dialog and without clicking done button, it fails.

private final DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
       private boolean fired;
         public void resetFired(){
                fired = false;
            }
            @Override
            public void onDateSet(DatePicker view, int selectedYear,
                    int selectedMonth, int selectedDay) {
                if (fired) {
                    Log.e("DatePicker", "Ignoring for first time");
                    birthDayValue = selectedDay;
                    birthMonthValue = selectedMonth;
                    birthYearValue = selectedYear;
                    String birthDayDateFormt = Utils.getBirthDayDate(selectedYear,
                            selectedMonth, selectedDay);
                    dateOfBirth.setText(birthDayDateFormt);
                    dateOfBirth.setError(null);
                    return;//ignore and return.
                } 
                fired = true;//first time fired
            }
    };

};

How to solve this issue?

Community
  • 1
  • 1
Shadow
  • 6,864
  • 6
  • 44
  • 93
  • Are you calling the _resetFire()_ method on your listeners instance? Just make sure after each dissmisal you call _resetFire()_. – Gent Ahmeti Feb 01 '15 at 12:15
  • no. where should i use that? will you please show me a code, so that if worked i will choose and close this from unanswered question. – Shadow Feb 01 '15 at 12:18
  • I'm sorry. I have misunderstood the question. But I don't think this method will do what you want it to do. On that question you had a lot of good answers, try the accepted one. – Gent Ahmeti Feb 01 '15 at 12:28
  • i tried that and so only posted the question. however thanks. @torque203 – Shadow Feb 02 '15 at 05:16
  • Did you try [this](https://docs.google.com/file/d/0B-Q8sq_qCRv3V1NEbk5kTlJXSm8/edit?pli=1) ? – SweetWisher ツ Feb 02 '15 at 07:28

1 Answers1

0
        @Override
        public void onDateSet(DatePicker view, int selectedYear,
                int selectedMonth, int selectedDay) {
        if(view.isShown()) {
            if (fired) {
                Log.e("DatePicker", "Ignoring for first time");
                birthDayValue = selectedDay;
                birthMonthValue = selectedMonth;
                birthYearValue = selectedYear;
                String birthDayDateFormt = Utils.getBirthDayDate(selectedYear,
                        selectedMonth, selectedDay);
                dateOfBirth.setText(birthDayDateFormt);
                dateOfBirth.setError(null);
                return;//ignore and return.
            } 
            fired = true;//first time fired
          }
        }

if(view.isShown()) add code in this condition, its a simple step do it and check output

Prashant Gosai
  • 1,186
  • 1
  • 10
  • 18