简体   繁体   中英

Automatically get keyboard for an EditText in a Dialog (Android)

Close cousins of this question seem to be all over StackExchange, but maybe that's why I can't find an answer...

I have an application. Within the application, I've got a couple different Surface Views, and each of them has a couple different actions that fire up a Dialog.

My dialogs consists of an EditText (for typing in some data) and Set and Cancel buttons for acting on that data. To type in the data, the user first touches the EditText to bring up the keyboard, then types the data, touches Done, then touches Set, and the application continues on its merry way.

I would like to find a way to shorten this, if at all possible. Specifically, I would like to skip over the view of the dialog and go right to the view of the keyboard. (Essentially, I want to programmatically "touch" the EditText, if that makes any sense.)

Like I said at the beginning of this, I'm not having a lot of luck, so any suggestions will be happily looked in to. And, unfortunately, simply requesting focus in the EditText has been tried and hasn't done the trick...

R.

尝试这个

 dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

The easy and best way , is to give focus to your EditText when your open the dialogues :

EditText yourET = (EditText) findViewById(R.id.my_editText);
yourET.requestFocus();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM