I am using the AlertDialog.Builder in Android to quickly prompt the user for text. The dialog shows up and works great, but the user must click on the EditText field to load the soft keyboard. Is there any way to open the keyboard and give focus to the whenever my dialog is opened? Here is my code:
final Map<String,Object> rowData = itemList.get(mPosition);
final EditText input = new EditText(searchList.getContext());
input.requestFocus();
input.setSingleLine();
final AlertDialog dialog = new AlertDialog.Builder(searchList.getContext())
.setTitle(StringUtils.getSafeString(rowData.get("label")))
.setView(input)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
rowData.put("value", StringUtils.getSafeString(input.getText()));
searchList.invalidateViews();
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
}).create();
dialog.show();