Example usage for android.app AlertDialog.Builder setOnCancelListener

List of usage examples for android.app AlertDialog.Builder setOnCancelListener

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setOnCancelListener.

Prototype

public void setOnCancelListener(@Nullable OnCancelListener listener) 

Source Link

Document

Set a listener to be invoked when the dialog is canceled.

Usage

From source file:org.petero.droidfish.DroidFish.java

private final Dialog networkEngineConfigDialog() {
    View content = View.inflate(this, R.layout.network_engine_config, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);/*from w  w  w  . j av a  2  s  .c o m*/
    builder.setTitle(R.string.configure_network_engine);
    final EditText hostNameView = (EditText) content.findViewById(R.id.network_engine_host);
    final EditText portView = (EditText) content.findViewById(R.id.network_engine_port);
    String hostName = "";
    String port = "0";
    try {
        if (EngineUtil.isNetEngine(networkEngineToConfig)) {
            String[] lines = Util.readFile(networkEngineToConfig);
            if (lines.length > 1)
                hostName = lines[1];
            if (lines.length > 2)
                port = lines[2];
        }
    } catch (IOException e1) {
    }
    hostNameView.setText(hostName);
    portView.setText(port);
    final Runnable writeConfig = new Runnable() {
        public void run() {
            String hostName = hostNameView.getText().toString();
            String port = portView.getText().toString();
            try {
                FileWriter fw = new FileWriter(new File(networkEngineToConfig), false);
                fw.write("NETE\n");
                fw.write(hostName);
                fw.write("\n");
                fw.write(port);
                fw.write("\n");
                fw.close();
                setEngineOptions(true);
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            writeConfig.run();
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNeutralButton(R.string.delete, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(DELETE_NETWORK_ENGINE_DIALOG);
            showDialog(DELETE_NETWORK_ENGINE_DIALOG);
        }
    });

    final Dialog dialog = builder.create();
    portView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                writeConfig.run();
                dialog.cancel();
                removeDialog(NETWORK_ENGINE_DIALOG);
                showDialog(NETWORK_ENGINE_DIALOG);
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog newNetworkEngineDialog() {
    View content = View.inflate(this, R.layout.create_network_engine, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);// ww  w  .ja va  2  s  .  com
    builder.setTitle(R.string.create_network_engine);
    final EditText engineNameView = (EditText) content.findViewById(R.id.create_network_engine);
    engineNameView.setText("");
    final Runnable createEngine = new Runnable() {
        public void run() {
            String engineName = engineNameView.getText().toString();
            String sep = File.separator;
            String pathName = Environment.getExternalStorageDirectory() + sep + engineDir + sep + engineName;
            File file = new File(pathName);
            boolean nameOk = true;
            int errMsg = -1;
            if (engineName.contains("/")) {
                nameOk = false;
                errMsg = R.string.slash_not_allowed;
            } else if (internalEngine(engineName) || file.exists()) {
                nameOk = false;
                errMsg = R.string.engine_name_in_use;
            }
            if (!nameOk) {
                Toast.makeText(getApplicationContext(), errMsg, Toast.LENGTH_LONG).show();
                removeDialog(NETWORK_ENGINE_DIALOG);
                showDialog(NETWORK_ENGINE_DIALOG);
                return;
            }
            networkEngineToConfig = pathName;
            removeDialog(NETWORK_ENGINE_CONFIG_DIALOG);
            showDialog(NETWORK_ENGINE_CONFIG_DIALOG);
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            createEngine.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });

    final Dialog dialog = builder.create();
    engineNameView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                createEngine.run();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog networkEngineConfigDialog() {
    View content = View.inflate(this, R.layout.network_engine_config, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);//  w w  w .  ja va2s.com
    builder.setTitle(R.string.configure_network_engine);
    final EditText hostNameView = (EditText) content.findViewById(R.id.network_engine_host);
    final EditText portView = (EditText) content.findViewById(R.id.network_engine_port);
    String hostName = "";
    String port = "0";
    try {
        String[] lines = Util.readFile(networkEngineToConfig);
        if ((lines.length >= 1) && lines[0].equals("NETE")) {
            if (lines.length > 1)
                hostName = lines[1];
            if (lines.length > 2)
                port = lines[2];
        }
    } catch (IOException e1) {
    }
    hostNameView.setText(hostName);
    portView.setText(port);
    final Runnable writeConfig = new Runnable() {
        public void run() {
            String hostName = hostNameView.getText().toString();
            String port = portView.getText().toString();
            try {
                FileWriter fw = new FileWriter(new File(networkEngineToConfig), false);
                fw.write("NETE\n");
                fw.write(hostName);
                fw.write("\n");
                fw.write(port);
                fw.write("\n");
                fw.close();
                setEngineOptions(true);
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            writeConfig.run();
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNeutralButton(R.string.delete, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(DELETE_NETWORK_ENGINE_DIALOG);
            showDialog(DELETE_NETWORK_ENGINE_DIALOG);
        }
    });

    final Dialog dialog = builder.create();
    portView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                writeConfig.run();
                dialog.cancel();
                removeDialog(NETWORK_ENGINE_DIALOG);
                showDialog(NETWORK_ENGINE_DIALOG);
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:za.co.neilson.alarm.preferences.AlarmPreferencesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.alarm_preferences);

    pref = getSharedPreferences("AppPref", MODE_PRIVATE);
    email = getIntent().getStringExtra("email");
    Log.d("? ???!!! ", "" + email);

    Bundle bundle = getIntent().getExtras();
    if (bundle != null && bundle.containsKey("alarm")) {
        setMathAlarm((Alarm) bundle.getSerializable("alarm"));
    } else {/*from www  . java2 s.c o m*/
        setMathAlarm(new Alarm());
    }
    if (bundle != null && bundle.containsKey("adapter")) {
        setListAdapter((AlarmPreferenceListAdapter) bundle.getSerializable("adapter"));
    } else {
        setListAdapter(new AlarmPreferenceListAdapter(this, getMathAlarm()));
    }

    getListView().setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> l, View v, int position, long id) {
            final AlarmPreferenceListAdapter alarmPreferenceListAdapter = (AlarmPreferenceListAdapter) getListAdapter();
            final AlarmPreference alarmPreference = (AlarmPreference) alarmPreferenceListAdapter
                    .getItem(position);

            AlertDialog.Builder alert;
            v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
            switch (alarmPreference.getType()) {
            case BOOLEAN:
                CheckedTextView checkedTextView = (CheckedTextView) v;
                boolean checked = !checkedTextView.isChecked();
                ((CheckedTextView) v).setChecked(checked);
                switch (alarmPreference.getKey()) {
                case ALARM_ACTIVE:
                    alarm.setAlarmActive(checked);
                    break;
                case ALARM_VIBRATE:
                    alarm.setVibrate(checked);
                    if (checked) {
                        Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
                        vibrator.vibrate(1000);
                    }
                    break;
                }
                alarmPreference.setValue(checked);
                break;
            case STRING:

                alert = new AlertDialog.Builder(AlarmPreferencesActivity.this);

                alert.setTitle(alarmPreference.getTitle());
                // alert.setMessage(message);

                // Set an EditText view to get user input
                final EditText input = new EditText(AlarmPreferencesActivity.this);

                input.setText(alarmPreference.getValue().toString());

                alert.setView(input);
                alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        alarmPreference.setValue(input.getText().toString());

                        if (alarmPreference.getKey() == Key.ALARM_NAME) {
                            alarm.setAlarmName(alarmPreference.getValue().toString());
                        }

                        alarmPreferenceListAdapter.setMathAlarm(getMathAlarm());
                        alarmPreferenceListAdapter.notifyDataSetChanged();
                    }
                });
                alert.show();
                break;
            case LIST:
                alert = new AlertDialog.Builder(AlarmPreferencesActivity.this);

                alert.setTitle(alarmPreference.getTitle());
                // alert.setMessage(message);

                CharSequence[] items = new CharSequence[alarmPreference.getOptions().length];
                for (int i = 0; i < items.length; i++)
                    items[i] = alarmPreference.getOptions()[i];

                alert.setItems(items, new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (alarmPreference.getKey()) {
                        case ALARM_DIFFICULTY:
                            Alarm.Difficulty d = Alarm.Difficulty.values()[which];
                            alarm.setDifficulty(d);
                            break;
                        case ALARM_TONE:
                            alarm.setAlarmTonePath(alarmPreferenceListAdapter.getAlarmTonePaths()[which]);
                            if (alarm.getAlarmTonePath() != null) {
                                if (mediaPlayer == null) {
                                    mediaPlayer = new MediaPlayer();
                                } else {
                                    if (mediaPlayer.isPlaying())
                                        mediaPlayer.stop();
                                    mediaPlayer.reset();
                                }
                                try {
                                    // mediaPlayer.setVolume(1.0f, 1.0f);
                                    mediaPlayer.setVolume(0.2f, 0.2f);
                                    mediaPlayer.setDataSource(AlarmPreferencesActivity.this,
                                            Uri.parse(alarm.getAlarmTonePath()));
                                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                                    mediaPlayer.setLooping(false);
                                    mediaPlayer.prepare();
                                    mediaPlayer.start();

                                    // Force the mediaPlayer to stop after 3
                                    // seconds...
                                    if (alarmToneTimer != null)
                                        alarmToneTimer.cancel();
                                    alarmToneTimer = new CountDownTimer(3000, 3000) {
                                        @Override
                                        public void onTick(long millisUntilFinished) {

                                        }

                                        @Override
                                        public void onFinish() {
                                            try {
                                                if (mediaPlayer.isPlaying())
                                                    mediaPlayer.stop();
                                            } catch (Exception e) {

                                            }
                                        }
                                    };
                                    alarmToneTimer.start();
                                } catch (Exception e) {
                                    try {
                                        if (mediaPlayer.isPlaying())
                                            mediaPlayer.stop();
                                    } catch (Exception e2) {

                                    }
                                }
                            }
                            break;
                        default:
                            break;
                        }
                        alarmPreferenceListAdapter.setMathAlarm(getMathAlarm());
                        alarmPreferenceListAdapter.notifyDataSetChanged();
                    }

                });

                alert.show();
                break;
            case MULTIPLE_LIST:
                alert = new AlertDialog.Builder(AlarmPreferencesActivity.this);

                alert.setTitle(alarmPreference.getTitle());
                // alert.setMessage(message);

                CharSequence[] multiListItems = new CharSequence[alarmPreference.getOptions().length];
                for (int i = 0; i < multiListItems.length; i++)
                    multiListItems[i] = alarmPreference.getOptions()[i];

                boolean[] checkedItems = new boolean[multiListItems.length];
                for (Alarm.Day day : getMathAlarm().getDays()) {
                    checkedItems[day.ordinal()] = true;
                }
                alert.setMultiChoiceItems(multiListItems, checkedItems, new OnMultiChoiceClickListener() {

                    @Override
                    public void onClick(final DialogInterface dialog, int which, boolean isChecked) {

                        Alarm.Day thisDay = Alarm.Day.values()[which];

                        if (isChecked) {
                            alarm.addDay(thisDay);
                        } else {
                            // Only remove the day if there are more than 1
                            // selected
                            if (alarm.getDays().length > 1) {
                                alarm.removeDay(thisDay);
                            } else {
                                // If the last day was unchecked, re-check
                                // it
                                ((AlertDialog) dialog).getListView().setItemChecked(which, true);
                            }
                        }

                    }
                });
                alert.setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        alarmPreferenceListAdapter.setMathAlarm(getMathAlarm());
                        alarmPreferenceListAdapter.notifyDataSetChanged();

                    }
                });
                alert.show();
                break;
            case TIME:
                TimePickerDialog timePickerDialog = new TimePickerDialog(AlarmPreferencesActivity.this,
                        new OnTimeSetListener() {

                            @Override
                            public void onTimeSet(TimePicker timePicker, int hours, int minutes) {
                                Calendar newAlarmTime = Calendar.getInstance();
                                newAlarmTime.set(Calendar.HOUR_OF_DAY, hours);
                                newAlarmTime.set(Calendar.MINUTE, minutes);
                                newAlarmTime.set(Calendar.SECOND, 0);
                                alarm.setAlarmTime(newAlarmTime);
                                alarmPreferenceListAdapter.setMathAlarm(getMathAlarm());
                                alarmPreferenceListAdapter.notifyDataSetChanged();
                            }
                        }, alarm.getAlarmTime().get(Calendar.HOUR_OF_DAY),
                        alarm.getAlarmTime().get(Calendar.MINUTE), true);
                timePickerDialog.setTitle(alarmPreference.getTitle());
                timePickerDialog.show();
            default:
                break;
            }
        }
    });
}

From source file:com.rfo.basic.Run.java

private void doDebugSwapDialog() {

    ArrayList<String> msg = new ArrayList<String>();
    msg.addAll(Arrays.asList("Program", "Scalars", "Array", "List", "Stack", "Bundle", "Watch"));
    final String[] names = { "View Program", "View Scalars", "View Array", "View List", "View Stack",
            "View Bundle", "View Watch", "View Console" };

    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.debug_list_s_layout, null);

    ListView debugView = (ListView) dialogLayout.findViewById(R.id.debug_list_s);
    debugView.setAdapter(new ArrayAdapter<String>(Run.this, R.layout.simple_list_layout_1, msg));
    debugView.setVerticalScrollBarEnabled(true);
    debugView.setClickable(true);// ww  w . jav a  2  s.c  o m

    debugView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DialogSelector(position);
            boolean dosel = (dbDialogArray && WatchedArray == null) || (dbDialogList && WatchedList == -1)
                    || (dbDialogStack && WatchedStack == -1) || (dbDialogBundle && WatchedBundle == -1);
            if (dosel) {
                // if the element has not been defined ask if user wishes to do so.
                // or at least this is where it will go.
                // for now, default to view program.
                DialogSelector(0);
                position = 0;
            }
            String name = (position < names.length) ? names[position] : "";
            Toaster(name).show();
        }
    });

    AlertDialog.Builder builder = new AlertDialog.Builder(Run.this).setCancelable(true).setTitle("Select View:")
            .setView(dialogLayout);

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface arg0) {
            WaitForSwap = false;
        }
    });

    builder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            WaitForSwap = false;
            dbSwap = false;
        }
    });

    /*  // leave out until the element selector is done.
          builder.setNeutralButton("Choose Element",
             new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog,int which) {
       WaitForSelect = true;
    }
             });
    */
    dbSwapDialog = builder.show();
    dbSwapDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
}

From source file:com.rfo.basic.Run.java

private void doDebugDialog() {

    int lineIndex = 0;
    String text = "";
    if (mInterpreter != null) {
        lineIndex = mInterpreter.ExecutingLineIndex;
        text = mInterpreter.ExecutingLineBuffer.text();
    }/*  w w  w.  j a  va2  s .c o m*/

    ArrayList<String> msg = new ArrayList<String>();

    if (!dbDialogProgram) {
        msg = mInterpreter.dbDoFunc();
        msg.add("Executable Line #:    " + Integer.toString(lineIndex + 1) + '\n' + chomp(text));
    }

    if (dbDialogScalars)
        msg.addAll(mInterpreter.dbDoScalars("  "));
    if (dbDialogArray)
        msg.addAll(mInterpreter.dbDoArray("  "));
    if (dbDialogList)
        msg.addAll(mInterpreter.dbDoList("  "));
    if (dbDialogStack)
        msg.addAll(mInterpreter.dbDoStack("  "));
    if (dbDialogBundle)
        msg.addAll(mInterpreter.dbDoBundle("  "));
    if (dbDialogWatch)
        msg.addAll(mInterpreter.dbDoWatch("  "));

    if (dbDialogProgram) {
        for (int i = 0; i < Basic.lines.size(); ++i) {
            msg.add(((i == lineIndex) ? " >>" : "   ") // mark current line
                    + (i + 1) + ": " // one-based line index
                    + chomp(Basic.lines.get(i).text())); // remove newline
        }
    }

    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.debug_dialog_layout, null);

    ListView debugView = (ListView) dialogLayout.findViewById(R.id.debug_list);
    debugView.setAdapter(new ArrayAdapter<String>(Run.this, R.layout.debug_list_layout, msg));
    debugView.setVerticalScrollBarEnabled(true);
    if (dbDialogProgram) {
        debugView.setSelection(lineIndex);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(Run.this).setCancelable(true)
            .setTitle(R.string.debug_name).setView(dialogLayout);

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface arg0) {
            DebuggerHalt = true;
            WaitForDebugResume = false;
            releaseDebugLOCK();
        }
    });

    builder.setPositiveButton("Resume", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            WaitForDebugResume = false;
            releaseDebugLOCK();
        }
    });

    builder.setNeutralButton("Step", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            DebuggerStep = true;
            WaitForDebugResume = true;
            releaseDebugLOCK();
        }
    });

    builder.setNegativeButton("View Swap", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dbSwap = true;
            releaseDebugLOCK();
        }
    });

    dbDialog = builder.show();
    dbDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
}

From source file:com.rfo.basic.Run.java

private void doInputDialog(DialogArgs args) {
    Context context = getContext();
    Log.d(LOGTAG, "InputDialog context " + context);

    EditText text = new EditText(context);
    text.setText(args.mInputDefault);/*from   ww  w .  j  a  v a  2  s.c  om*/
    Var.Val returnVal = args.mReturnVal;
    if (returnVal.isNumeric()) {
        text.setInputType(0x00003002); // Limits keys to signed decimal numbers
    }
    String btnLabel = args.mButton1;
    if (btnLabel == null) {
        btnLabel = "Ok";
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setView(text).setCancelable(true).setTitle(args.mTitle) // default null, no title displayed if null or empty
            .setPositiveButton(btnLabel, null); // need to override default View click handler to prevent
    // auto-dismiss, but can't do it until after show()

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            Log.d(LOGTAG, "Input Dialog onCancel");
            mInputCancelled = true; // signal read by executeINPUT
        }
    });

    final AlertDialog dialog = builder.create();
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        public void onDismiss(DialogInterface dialog) {
            Log.d(LOGTAG, "Input Dialog onDismiss");
            releaseLOCK(); // release the lock that executeINPUT is waiting for
        }
    });
    dialog.getWindow().setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    dialog.show();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE) // now we can replace the View click listener
            .setOnClickListener(new InputDialogClickListener(dialog, text, args)); // to prevent auto-dismiss
}

From source file:com.rfo.basic.Run.java

private void doAlertDialog(DialogArgs args) {
    Context context = getContext();
    Log.d(LOGTAG, "AlertDialog context " + context);

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    String positive = args.mButton1;
    String neutral = args.mButton2;
    String negative = args.mButton3;
    String[] list = args.mList;/*from  w  ww .j a  va 2  s .c  om*/
    AlertDialogClickListener listener = new AlertDialogClickListener();

    builder.setCancelable(true).setTitle(args.mTitle); // no title if null or empty
    if (positive != null) {
        builder.setPositiveButton(positive, listener);
    }
    if (neutral != null) {
        builder.setNeutralButton(neutral, listener);
    }
    if (negative != null) {
        builder.setNegativeButton(negative, listener);
    }

    if (list != null) {
        builder.setItems(list, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                mAlertItemID = which + 1; // convert to 1-based index
            }
        });
    } else {
        builder.setMessage(args.mMessage); // list and message are mutually exclusive
    }

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            Log.d(LOGTAG, "Alert Dialog onCancel");
            mAlertItemID = 0; // no button clicked or item selected
        }
    });

    final AlertDialog dialog = builder.create();
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        public void onDismiss(DialogInterface dialog) {
            Log.d(LOGTAG, "Alert Dialog onDismiss");
            releaseLOCK(); // release the lock that executeINPUT is waiting for
        }
    });
    dialog.show();
}