Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog dismissed when back pressed

I am using alert dialog with following properties.The problem is the dialog is dismiissed when i click back button or touch outside the dialog i don't want that.How can i solve this because setCancelable is not helping.

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage(R.string.check_internet);
    builder.setCancelable(false);
like image 412
Ravi Avatar asked May 13 '13 11:05

Ravi


People also ask

What is AlertDialog message?

Alert Dialog shows the Alert message and gives the answer in the form of yes or no. Alert Dialog displays the message to warn you and then according to your response the next step is processed. Android Alert Dialog is built with the use of three fields: Title, Message area, Action Button.

How do I turn off AlertDialog on Android?

AlertDialog generally consists of the main title, the message, and two buttons, technically termed as a positive button and a negative button. Both positive and negative buttons can be programmed to perform various actions. By default, the negative button lets close the AlertDialog without any additional lines of code.

How do you dismiss material dialog?

setCancelable(false); AlertDialog dialog = builder. show(); In order to dismiss the dialog, you can call dismiss function like this.


1 Answers

Since you are extending a DialogFragment you need to call

setCancelable(false);

inside its onCreate

only setCancelable(false);

like image 192
Blackbelt Avatar answered Nov 09 '22 14:11

Blackbelt