O
O
orbit0702019-06-21 04:32:01
Android
orbit070, 2019-06-21 04:32:01

How to remove/close dialog boxes?

Hello.
1. There is a dialog box which is inherited from DialogFragment. I display it with show(). If the user in it clicks on the button I need, then I perform the necessary actions. If it presses back or on a blank area of ​​the screen, I do nothing.
2. There is a dialog box which is inherited from Dialog (in it I display ProgressBar). The back button or tapping on an empty area of ​​the screen is locked. Show with show(), hide with hide().
First question: if in the first case the user presses the back button or on an empty area of ​​the screen, then the hide () method automatically fires, which I call myself in the second case?
Second question: is calling the hide() method enough to completely and correctly close the dialog box? I came across the dismiss method but I don't understand very well when it needs to be called and is it necessary at all? I would really appreciate an explanation, thanks.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Varakosov, 2019-06-21
@orbit070

1) When the user closes the dialog by tapping anywhere, cancel() is called, followed by dismiss(), hide() is not called.
2) No. The hide() method only hides the dialog so that it can be shown again, it remains in memory. If the dialog is no longer needed, call dismiss() to gracefully destroy it, or cancel() if you want to first call the handler hung on onCancel().
Short. If you make the dialog hide(), then it can be show(); if you do dismiss (), then show () will cause an error.
It is understood that the dialogue is a one-time entity, created, shown and destroyed after interaction with the user. The main use case for hide() is to display the progress of long running processes when you want to allow the user to hide the dialog.

P
Petr Vasiliev, 2019-06-21
@danial72

1) if I remember correctly, hide is called
2) the dialog box has 3 outcomes: the person confirms the action description and, perhaps, the person refuses (the same dismiss) and the person closes the modal without a decision. Dismiss is about choosing an action by a person on the modal window itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question