Generic PromptDialog

The GenericPromptDialog class encapsulates all the needs of a prompt dialog by extending the ManagedActivityDialog class and providing the necessary create and prepare methods (see Listing 5-34). You can also see that it saves the reply text in a local variable so that the parent activity can get to it in the dialogFinished callback method.

Listing 5-34. The GenericPromptDialog Class public class GenericPromptDialog extends ManagedActivityDialog {

private String mPromptMessage = null; private View promptView = null; String promptValue = null;

private Context ctx = null;

public GenericPromptDialog(ManagedDialogsActivity inActivity, int dialogId, String promptMessage)

super(inActivity,dialogId); mPromptMessage = promptMessage; ctx = inActivity;

public Dialog create() {

Layoutlnflater li = Layoutlnflater.from(ctx);

promptView = li.inflate(R.layout.promptdialog, null);

AlertDialog.Builder builder = new AlertDialog.Builder(ctx);



builder.setPositiveButton("OK", this);

builder.setNegativeButton("Cancel", this);

AlertDialog ad = builder.create();

return ad;

public void prepare(Dialog dialog) {

//nothing for now

public void onClickHook(int buttonId) {

if (buttonId == DialogInterface.BUTTONl) {

//ok button

String promptValue = getEnteredText();

private String getEnteredText() {

EditText et = (EditText)

promptView.findViewById(; String enteredText = et.getText().toString(); Log.d("xx",enteredText); return enteredText;

0 0

Post a comment