Skip to content

Instantly share code, notes, and snippets.

@roboxito
Last active August 29, 2015 14:15
Show Gist options
  • Save roboxito/f101083f3a98beb5e7a6 to your computer and use it in GitHub Desktop.
Save roboxito/f101083f3a98beb5e7a6 to your computer and use it in GitHub Desktop.
Android AlertDialog Fragment Example
MensajeDialogo dlg=new MensajeDialogo();
dlg.setMensaje("Contenido del diálogo.";
dlg.show(getFragmentManager(),"Título";
package org.androiddes.roboxito.ejemplos;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
/**
* Created by @roboxito on 15/02/15.
*/
public class MensajeDialogo extends DialogFragment {
private String mensaje;
public void setMensaje(String mensaje) {
this.mensaje = mensaje;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Set the message to display.
builder.setMessage(this.mensaje)
.setTitle(this.getTag())
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//Evento al presionar botón OK
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment