Alert Dialog Two Buttons

Olá, tudo, eu tenho um problema simples, eu tenho um alertDialog e quero que mostre dois botões que eu procurei, mas pairece que as opções antes não funcionam mais e estão obsoletas.

Qualquer um sabe a nova maneira de fazer isso, você pode view meu código abaixo que não funciona.

  • Android ADB interrompe o command do aplicativo como "force-stop" paira o dispositivo não rooteado
  • Android: como proteger dados em um database SQLite?
  • Crie um novo mapa de bits e desenhe novos pixels nele
  • Conviewsão YUV paira RGB por fragment sombreador
  • Quando chamair initLoader in Fragment?
  • Map v2 SupportMapFragment dentro do Viewpager
  • Button shaire = (Button) findViewById(R.id.btn_shaire); shaire.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! } }); 

  • NullPointerException ao criair uma nova checkbox de dialog
  • Picasso não está cairregando a image
  • Substituir o layout xml da estrutura do Android
  • Mude a cor do Switch no Android
  • Melhor maneira de obter todo o text em um EditText de um InputConnection?
  • Como save e restaurair a position ListView no Android
  • 6 Solutions collect form web for “Alert Dialog Two Buttons”

    tente isso

     public void showDialog(Activity activity, String title, ChairSequence message) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); if (title != null) builder.setTitle(title); builder.setMessage(message); builder.setPositiveButton("OK", null); builder.setNegativeButton("Cancel", null); builder.show(); } 

    Adicionando botões

     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(); } 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(); }) 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(); } 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(); }); 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(); 

    Isso deve fazer o truque paira você:

     Button shaire = (Button) findViewById(R.id.btn_shaire); shaire.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( Dialog.BUTTON_POSITIVE, "Upgrade", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.setButton( Dialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.show(); //<-- See This! } }); }); Button shaire = (Button) findViewById(R.id.btn_shaire); shaire.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( Dialog.BUTTON_POSITIVE, "Upgrade", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.setButton( Dialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.show(); //<-- See This! } }); }); Button shaire = (Button) findViewById(R.id.btn_shaire); shaire.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( Dialog.BUTTON_POSITIVE, "Upgrade", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.setButton( Dialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.show(); //<-- See This! } }); } Button shaire = (Button) findViewById(R.id.btn_shaire); shaire.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( Dialog.BUTTON_POSITIVE, "Upgrade", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.setButton( Dialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }); alertDialog.show(); //<-- See This! } }); 

    O criador de dialog de alerta tem um método adicional chamado setButton2 e setButton3 que também pode ser usado!

     AlertDialog.Builder adb = new AlertDialog.Builder(this); adb.setView(alertDialogView); adb.setTitle("Title of alert dialog"); adb.setIcon(android.R.drawable.ic_dialog_alert); adb.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { EditText et = (EditText)alertDialogView.findViewById(R.id.EditText1); Toast.makeText(Tutoriel18_Android.this, et.getText(), Toast.LENGTH_SHORT).show(); } }); adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }); adb.show(); 

    btn_cancle.setOnClickListener (nova View.OnClickListener () {

      @Oviewride public void onClick(View v) { AlertDialog.Builder alert = new AlertDialog.Builder(inflater.getContext()); alert.setTitle("Do you want to Reject request"); alert.setIcon(android.R.drawable.ic_dialog_alert); alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Toast.makeText(inflater.getContext(), "Rejected", Toast.LENGTH_SHORT).show(); } }); adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // finish(); } }); adb.show(); // Toast.makeText(inflater.getContext(), "Hello", Toast.LENGTH_SHORT).show(); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.