Reputation: 985
Im trying to create an AlertDialog dynamically corresponding to the number of Strings in W.englishList. Im adding EditTexts to a grid layout by this way :
final Activity act = this;
GridLayout lay = new GridLayout(act);
lay.setOrientation(GridLayout.VERTICAL);
int row = 1;
for (String i : W.englishList) {
EditText text = new EditText(act);
text.setText(i);
LayoutParams p = new GridLayout.LayoutParams();
p.bottomMargin = 5;
p.width = GridLayout.LayoutParams.WRAP_CONTENT;
p.columnSpec = GridLayout.spec(0);
p.rowSpec = GridLayout.spec(tmp);
text.setLayoutParams(p);
lay.addView(text);
row++;
}
//Some AlertDialog.setContentView(lay);
Everything works except that i can't edit the Editexts created, I can focus them, copy them but i can't edit them (the keyboard doesnt show), any ideas ?
Edit: I can copy paste into them.
Upvotes: 1
Views: 549
Reputation: 1474
It happens because allert dialog bloks keyboard. You can show keyboard always:
alertDialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
or set onTouchListener for each EditText and show keyboard on touch:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
and hide it:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
Upvotes: 1