Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple buttons on a single AlertDialog

Tags:

android

I have a butoon, on clicking of this button i want to open multiple buttons on a single AlertDialog like this :enter image description here

Give Me a help :

I was using this.... to add multiple buttons

alertDialog.setButton(delete, "Delete", new OnClickListener() {                  public void onClick(View v) {             // TODO Auto-generated method stub                      }     }); 

but I found..., change setButton() to setButton2().. something like..... wt xcan i do for this....

like image 906
Maddy Avatar asked Sep 03 '12 08:09

Maddy


People also ask

How many maximum buttons are supported in an AlertDialog?

There should not be more than three action buttons in AlertDialog, and they are positive, negative, and neutral. Positive is used to accept and continue with the action.

Is AlertDialog deprecated?

A simple dialog containing an DatePicker . This class was deprecated in API level 26.

How many buttons can be set up on an AlertDialog?

AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.

How can I customize AlertDialog in Android?

Step 1: Create a XML file: custom_layout. Add the below code in custom_layout. xml. This code defines the alertdialog box dimensions and add a edittext in it.


1 Answers

A simple solution without xml:

AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Title"); builder.setItems(new CharSequence[]         {"button 1", "button 2", "button 3", "button 4"},         new DialogInterface.OnClickListener() {             public void onClick(DialogInterface dialog, int which) {                 // The 'which' argument contains the index position                 // of the selected item                 switch (which) {                     case 0:                         Toast.makeText(context, "clicked 1", Toast.LENGTH_SHORT).show();                         break;                     case 1:                         Toast.makeText(context, "clicked 2", Toast.LENGTH_SHORT).show();                         break;                     case 2:                         Toast.makeText(context, "clicked 3", Toast.LENGTH_SHORT).show();                         break;                     case 3:                         Toast.makeText(context, "clicked 4", Toast.LENGTH_SHORT).show();                         break;                 }             }         }); builder.create().show(); 
like image 122
Oded Breiner Avatar answered Sep 30 '22 13:09

Oded Breiner