I have this piece of code ( RelativeLayout is just one line 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 (Dialog Settings ) I have an EditText and a button. How can I make the keyboard open immidiatelly when the dialog is displayed and focus on my (one) EditText field?
I tried with the classic "forcing" that I found here on SO, but this is not activity, this is dialogue.
EDIT: I tried this, but it does not work. Declared myDialog as a 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.
source share