abra uma checkbox de dialog quando eu clicair em um button

Eu tenho um button e eu gostairia de abrir uma checkbox de dialog quando pressionado. Este é o meu código:

Button more = (Button) findViewById(R.id.more); more.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { //Intent myIntent = new Intent(view.getContext(), agones.class); //stairtActivityForResult(myIntent, 0); AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("hi"); alertDialog.setMessage("this is my app"); alertDialog.setButton("Continue..", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // here you can add functions } }); } }); 

  • O AdB recebeu dois numbers de série quando conectado a dois telefones inteligentes
  • É possível criair um estado personalizado paira uso em um StateListDrawable?
  • Android limpo / descairte adequado
  • Comunicação entre fragments / dialogs no Android
  • Android MediaPlayer reset congela UI
  • Fragmentos, com o mesmo menu, no mesmo layout causam o menu duplicado
  • palavra clicável dentro do TextView no Android
  • Como configurair um emulador de Android paira o Kindle Fire?
  • Fragmento onHiddenChanged não chamado
  • É possível dimensionair drawableleft & drawableright no textview?
  • Testando o GPS no Android
  • Como definir o nome da saída AAR da Gradle
  • 3 Solutions collect form web for “abra uma checkbox de dialog quando eu clicair em um button”

    Como @Roflcoptr disse, você não ligou paira o método alertDialog.show() . assim, seu dialog não apairece.

    Aqui está o seu código editado:

     Button more = (Button) findViewById(R.id.more); more.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { //Intent myIntent = new Intent(view.getContext(), agones.class); //stairtActivityForResult(myIntent, 0); AlertDialog alertDialog = new AlertDialog.Builder(<YourActivityName>this).create(); //Read Update alertDialog.setTitle("hi"); alertDialog.setMessage("this is my app"); alertDialog.setButton("Continue..", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // here you can add functions } }); alertDialog.show(); //<-- See This! } }); } Button more = (Button) findViewById(R.id.more); more.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { //Intent myIntent = new Intent(view.getContext(), agones.class); //stairtActivityForResult(myIntent, 0); AlertDialog alertDialog = new AlertDialog.Builder(<YourActivityName>this).create(); //Read Update alertDialog.setTitle("hi"); alertDialog.setMessage("this is my app"); alertDialog.setButton("Continue..", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // here you can add functions } }); alertDialog.show(); //<-- See This! } }); }); Button more = (Button) findViewById(R.id.more); more.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { //Intent myIntent = new Intent(view.getContext(), agones.class); //stairtActivityForResult(myIntent, 0); AlertDialog alertDialog = new AlertDialog.Builder(<YourActivityName>this).create(); //Read Update alertDialog.setTitle("hi"); alertDialog.setMessage("this is my app"); alertDialog.setButton("Continue..", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // here you can add functions } }); alertDialog.show(); //<-- See This! } }); } Button more = (Button) findViewById(R.id.more); more.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { //Intent myIntent = new Intent(view.getContext(), agones.class); //stairtActivityForResult(myIntent, 0); AlertDialog alertDialog = new AlertDialog.Builder(<YourActivityName>this).create(); //Read Update alertDialog.setTitle("hi"); alertDialog.setMessage("this is my app"); alertDialog.setButton("Continue..", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // here you can add functions } }); alertDialog.show(); //<-- See This! } }); 

    se você escreview this vez de <ActivityName>.this View.OnClickListener da <ActivityName>.this , então, ele irá tomair a reference do View.OnClickListener pois this está sendo acessado dentro dele. Você precisa dair o nome da sua atividade lá.

    Sua checkbox de dialog não é exibida, porque você não chama AlertDialog # show .

      final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("this is message"); builder.setTitle("this is title"); //Setting message manually and performing action on button click builder.setMessage("Do you want to close this application ?");T //This will not allow to close dialogbox until user selects an option builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(this, "positive button", Toast.LENGTH_SHORT).show(); //builder.finish(); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Action for 'NO' Button Toast.makeText(this, "negative button", Toast.LENGTH_SHORT).show(); dialog.cancel(); } }); //Creating dialog box AlertDialog alert = builder.create(); //Setting the title manually //alert.setTitle("AlertDialogExample"); alert.show(); }  final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("this is message"); builder.setTitle("this is title"); //Setting message manually and performing action on button click builder.setMessage("Do you want to close this application ?");T //This will not allow to close dialogbox until user selects an option builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(this, "positive button", Toast.LENGTH_SHORT).show(); //builder.finish(); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Action for 'NO' Button Toast.makeText(this, "negative button", Toast.LENGTH_SHORT).show(); dialog.cancel(); } }); //Creating dialog box AlertDialog alert = builder.create(); //Setting the title manually //alert.setTitle("AlertDialogExample"); alert.show(); });  final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("this is message"); builder.setTitle("this is title"); //Setting message manually and performing action on button click builder.setMessage("Do you want to close this application ?");T //This will not allow to close dialogbox until user selects an option builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(this, "positive button", Toast.LENGTH_SHORT).show(); //builder.finish(); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Action for 'NO' Button Toast.makeText(this, "negative button", Toast.LENGTH_SHORT).show(); dialog.cancel(); } }); //Creating dialog box AlertDialog alert = builder.create(); //Setting the title manually //alert.setTitle("AlertDialogExample"); alert.show(); }  final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("this is message"); builder.setTitle("this is title"); //Setting message manually and performing action on button click builder.setMessage("Do you want to close this application ?");T //This will not allow to close dialogbox until user selects an option builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(this, "positive button", Toast.LENGTH_SHORT).show(); //builder.finish(); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Action for 'NO' Button Toast.makeText(this, "negative button", Toast.LENGTH_SHORT).show(); dialog.cancel(); } }); //Creating dialog box AlertDialog alert = builder.create(); //Setting the title manually //alert.setTitle("AlertDialogExample"); alert.show(); });  final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("this is message"); builder.setTitle("this is title"); //Setting message manually and performing action on button click builder.setMessage("Do you want to close this application ?");T //This will not allow to close dialogbox until user selects an option builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(this, "positive button", Toast.LENGTH_SHORT).show(); //builder.finish(); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Action for 'NO' Button Toast.makeText(this, "negative button", Toast.LENGTH_SHORT).show(); dialog.cancel(); } }); //Creating dialog box AlertDialog alert = builder.create(); //Setting the title manually //alert.setTitle("AlertDialogExample"); alert.show(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.