[英]Can't edit an EditText Android
Im trying to create an AlertDialog dynamically corresponding to the number of Strings in W.englishList.我正在尝试根据 W.englishList 中的字符串数量动态创建一个 AlertDialog。 Im adding EditTexts to a grid layout by this way :
我通过这种方式将 EditTexts 添加到网格布局:
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 ?一切正常,除了我无法编辑创建的 Editexts,我可以聚焦它们,复制它们但我无法编辑它们(键盘不显示),有什么想法吗?
Edit: I can copy paste into them.编辑:我可以将粘贴复制到它们中。
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:或为每个 EditText 设置 onTouchListener 并在触摸时显示键盘:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.