DatePickerDialog in Android

  android, java

There is problem when the dialog opens, and pressing ok again nothing happens, but when you press edittext again, everything works properly. I think there is one dialogue calendar surplus. Does anyone maybe know? Thank you

    @Override
        protected void onCreate(Bundle savedInstanceState) {
    calendar = Calendar.getInstance();
    
    
            //final Calendar mCalendar = new GregorianCalendar();
    
            final DatePickerDialog.OnDateSetListener datePocetnoVreme = new DatePickerDialog.OnDateSetListener() {
    
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear,
                                      int dayOfMonth) {
                    calendar.set(Calendar.YEAR, year);
                    calendar.set(Calendar.MONTH, monthOfYear);
                    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                    if (brojacZavrsnoVreme == 0) {
                        brojacZavrsnoVreme = 1;
                    } else {
                        showTimePicker(true);
                        brojacZavrsnoVreme = 0;
                    }
    
                }
    
            };
            pocetnoVremeEditText.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    new DatePickerDialog(Unos.this,R.style.DialogTheme,datePocetnoVreme,calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)).show();
                }
            });
    
    
            final DatePickerDialog.OnDateSetListener dateZavrsnoVreme = new DatePickerDialog.OnDateSetListener() {
    
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear,
                                      int dayOfMonth) {
                    calendar = Calendar.getInstance();
                    calendar.set(Calendar.YEAR, year);
                    calendar.set(Calendar.MONTH, monthOfYear);
                    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                    if (brojacZavrsnoVreme == 0) {
                        brojacZavrsnoVreme = 1;
                    } else {
                        showTimePicker(false);
                        brojacZavrsnoVreme = 0;
                    }
    
                }
    
            };
    
            zavrsnoVremeEditText.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    new DatePickerDialog(Unos.this, dateZavrsnoVreme, calendar
                            .get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                            calendar.get(Calendar.DAY_OF_MONTH)).show();
                }
            });
}

enter image description here

Source: Android Questions

LEAVE A COMMENT