tutorial theme look instalar feel español dark arc and android button builder alertdialog

android - theme - windowbuilder eclipse tutorial español



Botón único AlertDialog de Android (7)

¿No podría hacerse solo usando un botón positivo?

AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Look at this dialog!") .setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //do things } }); AlertDialog alert = builder.create(); alert.show();

Me gustaría tener un generador de AlertDialog que solo tenga un botón que diga OK o Listo o algo así, en lugar de los sí y no predeterminados. ¿Se puede hacer eso con el AlertDialog estándar, o tendría que usar algo más?


En Mono para Android puedes hacer esto:

var ad = new AlertDialog.Builder(this); ad.SetTitle("Title"); ad.SetMessage("Message"); ad.SetPositiveButton("OK", delegate { ad.Dispose(); }); ad.Show();



Esto es lo más cerca que podría llegar al trazador de líneas que debería ser si la API de Android fuera inteligente:

new AlertDialog.Builder(this) .setMessage(msg) .setPositiveButton("OK", null) .show();


Para la reutilización de código, puede hacerlo en un método como este

public static Dialog getDialog(Context context,String title, String message, DialogType typeButtons ) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(title) .setMessage(message) .setCancelable(false); if (typeButtons == DialogType.SINGLE_BUTTON) { builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //do things } }); } AlertDialog alert = builder.create(); return alert; } public enum DialogType { SINGLE_BUTTON }

// Otros problemas de reutilización de códigos como el uso de interfaces para proporcionar comentarios también serán excelentes.


Puedes usar esto:

AlertDialog.Builder builder1 = new AlertDialog.Builder(this); builder1.setTitle("Title"); builder1.setMessage("my message"); builder1.setCancelable(true); builder1.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert11 = builder1.create(); alert11.show();


Otro enfoque

Builder alert = new AlertDialog.Builder(ActivityName.this); alert.setTitle("Doctor"); alert.setMessage("message"); alert.setPositiveButton("OK",null); alert.show();

Prima

AlertDialog.Builder builder = new AlertDialog.Builder(YourActivityName.this); builder.setMessage("Message dialog with three buttons"); builder.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //do things } }); builder.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //do things } }); builder.setNeutralButton("CANCEL", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //do things } }); AlertDialog alert = builder.create(); alert.show();

Ahora depende de usted usar uno, dos o tres botones.