【发布时间】:2011-05-07 06:06:45
【问题描述】:
我正在使用 Java 在 Android 2.2 上进行开发。 我在 PopupWindow 上放置了一个 editText,但它不起作用。 它就像一个禁用的编辑文本,点击编辑文本不会显示软键盘。 如何在弹出窗口上添加编辑文本?
【问题讨论】:
标签: java android android-edittext popupwindow
我正在使用 Java 在 Android 2.2 上进行开发。 我在 PopupWindow 上放置了一个 editText,但它不起作用。 它就像一个禁用的编辑文本,点击编辑文本不会显示软键盘。 如何在弹出窗口上添加编辑文本?
【问题讨论】:
标签: java android android-edittext popupwindow
EditText 是否确实将 android:editable 属性设置为 true?如果它是假的,它将按照您的描述被禁用。
【讨论】:
我已经解决了这样的问题:我输入了popupWindow.setFocusable(true);,现在它可以工作了。似乎弹出窗口上的编辑文本没有焦点,因为弹出窗口没有焦点。
【讨论】:
试试吧:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title");
alert.setMessage("Message");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do something with value!
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
【讨论】:
popWindow.setFocusable(true);
popWindow.update();
它会起作用的。
【讨论】:
从任何监听器调用此代码
private void popUpEditText() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Comments");
final EditText input = new EditText(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
builder.setView(input);
// Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do something here on OK
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
【讨论】: