I have this piece of code (RelativeLayout is a just one row inside my main layout, not important).
RelativeLayout cellphoneNumberLayout = (RelativeLayout) findViewById(R.id.cellphone_number);
cellphoneNumberLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SettingsDialog myDialog = new SettingsDialog(Main.this);
myDialog.show();
}
});
Inside my custom Dialog (SettingsDialog) I have EditText and a Button. How can I force a keyboard to open immidiatelly when dialog is shown and focus on my (single) EditText field?
I tried with classic "forcing" which I found here on SO but this isn't activity, it's a dialog.
EDIT: I tried this but it's not working. Declared myDialog as class variable and added below myDialog.show();
myDialog.myEditTextField.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
myDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
Nothing happens.
The following will bring up the keyboard for the editText when it is focused:
EditText editText;
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean focused)
{
if (focused)
{
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
Then just set editText to focused:
editText.setFocusable(true);
editText.requestFocus();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With