ROAR.L
ROAR.L

Reputation: 333

How to create auto popup window in android studio

I wanted to create an auto pop up window at the first page in the app. But I couldn't seem to find any tutorials online. Anyone please guide. Any help will appreciate.

Thanks.

Upvotes: 0

Views: 2020

Answers (1)

Ameer
Ameer

Reputation: 2769

public void openDialog(View view){
  AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
  alertDialogBuilder.setMessage("Are you sure,You wanted to make decision");

  alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface arg0, int arg1) {
        Toast.makeText(MainActivity.this,"You clicked yes button",Toast.LENGTH_LONG).show();
     }
  });

  alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {
        finish();
     }
  });

  AlertDialog alertDialog = alertDialogBuilder.create();
  alertDialog.show();

}

Just call this method openDialog(); after your setContentView(R.layout.activity_main); Example

setContentView(R.layout.activity_main);
openDialog();

Upvotes: 1

Related Questions