Lily Wong
Lily Wong

Reputation: 11

How can I make the pop up dialog invisible in android?

I would like to know how can I make the pop up dialog invisible in android? but still working, only diable.

@Override
public void onProviderDisabled(String provider) {
    //Toast.makeText(getApplicationContext(),"#####onProviderDisabled", Toast.LENGTH_LONG).show();
    AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
    dialog.setMessage("open gps");
    dialog.setPositiveButton("open GPS",
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(
                        DialogInterface paramDialogInterface,
                        int paramInt) {
                    Intent myIntent = new Intent(
                            Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivity(myIntent);
                    // get gps
                }
            });
    dialog.setNegativeButton(
            "not now",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(
                        DialogInterface paramDialogInterface,
                        int paramInt) {

                }
            });
    dialog.show();
}

};

Upvotes: 0

Views: 1902

Answers (3)

Gregory Saldanha
Gregory Saldanha

Reputation: 106

    public void onProviderDisabled(String provider) {
//Toast.makeText(getApplicationContext(),"#####onProviderDisabled", Toast.LENGTH_LONG).show();
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("open gps");
builder.setPositiveButton("open GPS",
        new DialogInterface.OnClickListener() {

            @Override
            public void onClick(
                    DialogInterface paramDialogInterface,
                    int paramInt) {
                Intent myIntent = new Intent(
                        Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(myIntent);
                // get gps
            }
        });
builder.setNegativeButton(
        "not now",
        new DialogInterface.OnClickListener() {
            @Override
            public void onClick(
                    DialogInterface paramDialogInterface,
                    int paramInt) {

            }
        });
AlertDialog alert = builder.create():
alert.show();
}

And now when ever you want call alert.dismiss() to close the dialog.

Upvotes: 0

AdamMc331
AdamMc331

Reputation: 16691

To disable the dialog without removing the code completely, just comment out the line where you show the dialog:

// dialog.show();

This way the dialog won't appear, and if you want to show it again in a future version of your app you can just uncomment that line.

Upvotes: 2

Arth Tilva
Arth Tilva

Reputation: 2496

In your code, show() is called, which will open the dialog. For closing the dialog you need to call dismiss() with same object. There is nothing like VISIBLE and INVISIBLE in AlertDialog.

Upvotes: 0

Related Questions