[英]Can't edit an EditText Android
我正在尝试根据 W.englishList 中的字符串数量动态创建一个 AlertDialog。 我通过这种方式将 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);
一切正常,除了我无法编辑创建的 Editexts,我可以聚焦它们,复制它们但我无法编辑它们(键盘不显示),有什么想法吗?
编辑:我可以将粘贴复制到它们中。
发生这种情况是因为警报对话框阻止了键盘。 您可以始终显示键盘:
alertDialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
或为每个 EditText 设置 onTouchListener 并在触摸时显示键盘:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
并隐藏它:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.