Я развиваюсь на Android 2.2 с помощью Java. Я поместил editText в PopupWindow, и он не работает. Он действует как отключенный текст редактирования, при нажатии на текст редактирования не отображается мягкая клавиатура. Как добавить текст редактирования в popupWindow?
EditText В всплывающем окне
Ответ 1
Я решил проблему следующим образом: я положил popupWindow.setFocusable(true);
и теперь он работает. Кажется, что текст редактирования, который был в поп-окне, не имел фокуса, потому что всплывающее окно не имело фокуса.
Ответ 2
Просто попробуйте:
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();
Ответ 3
У параметра EditText определенно установлено свойство android: editable для true? Если он ложный, он будет отключен, как вы описываете.
Ответ 4
popWindow.setFocusable(true);
popWindow.update();
Он будет работать.
Ответ 5
вызвать этот код из любого прослушивателя
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();
}