My code for opening an input dialog reads as follows:
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Dialog Title");
alert.setMessage("Request information");
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.edittextautotextlayout, null);
final EditText inputBox = (EditText) textEntryView.findViewById(R.id.my_et_layout);
alert.setView(inputBox);
This works fine except that I have to tap the text entry line before the soft keyboard appears.
Following the advice given here I have tried inserting:
inputBox.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
alert.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
but Eclipse objects that "the method getWindow() is not defined for the type AlertDialog.Builder".
It seems that the setOnFocusChangeListener code works for an AlertDialog object but not an AlertDialog.Builder. How should I modify my code to make the soft keyboard appear automatcially.
With the encouragement of Mur Votema (see his answer above) I have answered my question by building a custom dialog based on the Dialog class. Unlike an alert based on AlertDialog.Builder such a custom dialog does accept the getWindow().setSoftInputMode(...) command and therefore allows the soft keyboard to be displayed automatically.
For guidance on building a custom dialog I found this web page and this especially helpful.