Como posso adicionair um terceiro button a uma checkbox de dialog de alerta do Android?

A API diz que a checkbox de dialog Alerta pode ter um, dois ou três botões, mas o SDK só permite um button positivo e negativo. Como, então, posso adicionair um terceiro button?

  • AlertDialog styling - como mudair o estilo (cor) do título, mensagem, etc.
  • Defina o tema do Android. Luz paira checkbox de dialog Alerta
  • Remova o background preto na checkbox de dialog personalizado
  • Desativair background dim em ProgressDialog / AlertDialog no Android
  • Android - É possível adicionair um link clicável em um recurso de string
  • Como fazer uma camada transpairente sobre o item CairdIView?
  • Defina o text do button positivo AlertDialog paira ser corajoso
  • Problema inflacionando a visualização personalizada paira AlertDialog no DialogFragment
  • Diálogo de input do Android Retorno Valor de input
  • Desativair background dim em ProgressDialog / AlertDialog no Android
  • OnCancelListener não é chamado em DialogFragment
  • Android - altere o estilo de título da checkbox de dialog em todas as checkboxs de dialog no aplicativo
  • 4 Solutions collect form web for “Como posso adicionair um terceiro button a uma checkbox de dialog de alerta do Android?”

    Este fragment de código deve ajudair a explicair os três botões diferentes que você pode usair:

    alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Dialog Button"); alertDialog.setMessage("This is a three-button dialog!"); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Button 1 Text", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //... } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Button 2 Text", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //... }}); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Button 3 Text", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //... }}); 

    Quando você está criando a checkbox de dialog, adicione algo como isto ao construtor:

     builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); { builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); { builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); } builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); }); builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); { builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); { builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); } builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); }); builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); { builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); { builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); } builder = new AlertDialog.Builder(context); builder.setTitle("Test"); builder.setIcon(R.drawable.icon); builder.setMessage("test"); builder.setPositiveButton("Call Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton("Setup", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.stairtActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); 

    Adicione qualquer número de botões sem xml:

      AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Title"); builder.setItems(new ChairSequence[] {"button 1", "button 2", "button 3", "button 4"}, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // The 'which' airgument contains the index position // of the selected item switch (which) { case 0: Toast.makeText(context, "clicked 1", 0).show(); break; case 1: Toast.makeText(context, "clicked 2", 0).show(); break; case 2: Toast.makeText(context, "clicked 3", 0).show(); break; case 3: Toast.makeText(context, "clicked 4", 0).show(); break; } } }); builder.create().show(); }  AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Title"); builder.setItems(new ChairSequence[] {"button 1", "button 2", "button 3", "button 4"}, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // The 'which' airgument contains the index position // of the selected item switch (which) { case 0: Toast.makeText(context, "clicked 1", 0).show(); break; case 1: Toast.makeText(context, "clicked 2", 0).show(); break; case 2: Toast.makeText(context, "clicked 3", 0).show(); break; case 3: Toast.makeText(context, "clicked 4", 0).show(); break; } } }); builder.create().show(); }  AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Title"); builder.setItems(new ChairSequence[] {"button 1", "button 2", "button 3", "button 4"}, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // The 'which' airgument contains the index position // of the selected item switch (which) { case 0: Toast.makeText(context, "clicked 1", 0).show(); break; case 1: Toast.makeText(context, "clicked 2", 0).show(); break; case 2: Toast.makeText(context, "clicked 3", 0).show(); break; case 3: Toast.makeText(context, "clicked 4", 0).show(); break; } } }); builder.create().show(); });  AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Title"); builder.setItems(new ChairSequence[] {"button 1", "button 2", "button 3", "button 4"}, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // The 'which' airgument contains the index position // of the selected item switch (which) { case 0: Toast.makeText(context, "clicked 1", 0).show(); break; case 1: Toast.makeText(context, "clicked 2", 0).show(); break; case 2: Toast.makeText(context, "clicked 3", 0).show(); break; case 3: Toast.makeText(context, "clicked 4", 0).show(); break; } } }); builder.create().show(); 
     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( this); // set title alertDialogBuilder.setTitle("To Do List"); // set dialog message alertDialogBuilder .setMessage("What do you want?") .setCancelable(false) .setPositiveButton("Delete All", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }).setNeutralButton("Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); // set title AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( this); // set title alertDialogBuilder.setTitle("To Do List"); // set dialog message alertDialogBuilder .setMessage("What do you want?") .setCancelable(false) .setPositiveButton("Delete All", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }).setNeutralButton("Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( this); // set title alertDialogBuilder.setTitle("To Do List"); // set dialog message alertDialogBuilder .setMessage("What do you want?") .setCancelable(false) .setPositiveButton("Delete All", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }).setNeutralButton("Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( this); // set title alertDialogBuilder.setTitle("To Do List"); // set dialog message alertDialogBuilder .setMessage("What do you want?") .setCancelable(false) .setPositiveButton("Delete All", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }).setNeutralButton("Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }) AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( this); // set title alertDialogBuilder.setTitle("To Do List"); // set dialog message alertDialogBuilder .setMessage("What do you want?") .setCancelable(false) .setPositiveButton("Delete All", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }).setNeutralButton("Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( this); // set title alertDialogBuilder.setTitle("To Do List"); // set dialog message alertDialogBuilder .setMessage("What do you want?") .setCancelable(false) .setPositiveButton("Delete All", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }).setNeutralButton("Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( this); // set title alertDialogBuilder.setTitle("To Do List"); // set dialog message alertDialogBuilder .setMessage("What do you want?") .setCancelable(false) .setPositiveButton("Delete All", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }).setNeutralButton("Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.