Hello all i have a simple problem i have a alertDialog and i want it to show two buttons i have searched here but it seems the options before don't work anymore and are deprecated.
Anyone know the new way of doing this you can see my code below that doesn't work.
Button share = (Button) findViewById(R.id.btn_share); share.setOnClickListener(new OnClickListener() { public void onClick(View v) { // call some other methods before that I guess... AlertDialog alertDialog = new AlertDialog.Builder(PasswActivity.this).create(); //Read Update alertDialog.setTitle("Uprgade"); alertDialog.setMessage("Upgrade Text Here"); alertDialog.setButton("Upgrade", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.show(); //<-- See This! } });
AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.
AlertDialog in Android application comprises three regions: Title, Content area (Message), Action Button.
AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .
Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue.
Adding Buttons
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure you want to exit?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MyActivity.this.finish(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With