I'm creating an AlertDialog.Builder
at which I'm assigning a EditText
to get an input.
When it opens the keyboard doesn't automatically shows up.
Here is my code:
private void AskForInput(int inputType, String title) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(title);
final EditText input = new EditText(this);
input.setInputType(inputType);
builder.setView(input);
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
keyNumberValue = input.getText().toString() + "#";
//TODO: do things...
}
});
builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
I tried to solve using a suggestion I got from another post link:
AlertDialog alertToShow = builder.create();
alertToShow.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
alertToShow.show();
But still I have to tap on the EditText
to open the keyboard.
Any idea?