0

I want to open AlertDialog with EditText element, so that keyboard is show and whole text is selected?

that is wath I try:

public void showRenameDialog(Task task) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Enter the title of Task");

    final EditText input = new EditText(this);
    input.setId(TEXT_ID);
    input.setText(task.getTitle());
    input.setSelectAllOnFocus(true);
    builder.setView(input);
    final Task t = task;
    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
 ...
        }
    });

    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);
}

the text is selected, but the keyboard isn't showed.

Ant when I touch the text, keyboard go open, but the text is no more selected.

Mark
  • 17,887
  • 13
  • 66
  • 93
  • 1
    Have you tried anything? – A--C Feb 24 '13 at 23:00
  • you are right :) see question. – Mark Feb 24 '13 at 23:03
  • So I'm guessing the keyboard isn't showing? Maybe try [these solutuons](http://stackoverflow.com/questions/5593053/open-soft-keyboard-programmatically) And as for the selecting everything, I'd try to do `EditText#selectAll()` after `alertDialog.show()` – A--C Feb 24 '13 at 23:10

0 Answers0