florent37 / SingleDateAndTimePicker

You can now select a date and a time with only one widget !
Apache License 2.0
1.02k stars 333 forks source link

show twice display Dialog bottomSheet #237

Open fajaranugrah opened 4 years ago

fajaranugrah commented 4 years ago

Hello i get problem

Button button = (Button) findViewById(R.id.buttonDate);
button..setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            new SingleDateAndTimePickerDialog.Builder(this)
                                    .bottomSheet()
                                    .curved()
                                    .displayMinutes(false)
                                    .displayHours(false)
                                    .displayDays(false)
                                    .displayMonth(true)
                                    .displayYears(true)
                                    .displayDaysOfMonth(true)
                                    .display();
                        }
                    });

and then i click the Button, i get show dialog twice how i resolve this? Thank you

momadthenomad commented 4 years ago

Put it in a variable and then check if its already displayed and then close it and recreate it, or just do nothing.

momadthenomad commented 4 years ago

Something like this:

Button button = (Button) findViewById(R.id.buttonDate);
button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (datePickerDialog != null && !datePickerDialog.isDisplayed()) {
            datePickerDialog = new SingleDateAndTimePickerDialog.Builder(this)
                    .bottomSheet()
                    .curved()
                    .displayMinutes(false)
                    .displayHours(false)
                    .displayDays(false)
                    .displayMonth(true)
                    .displayYears(true)
                    .displayDaysOfMonth(true)
                    .build();
            datePickerDialog.display();
        }
    }
});