Reputation: 2773
I am developing on Android 2.2 using Java. I put an editText on a PopupWindow and it's not working. It acts like a disabled edit text, clicking on the edit text won't show the soft keyboard. How can I add an edit text on a popupWindow?
Upvotes: 17
Views: 44349
Reputation: 29
call this code from any listener
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();
}
Upvotes: 1
Reputation: 356
popWindow.setFocusable(true);
popWindow.update();
It will work.
Upvotes: 0
Reputation: 2773
I have resolved the problem like this: I put the popupWindow.setFocusable(true);
and now it's working. It seems that the edit text which was on a pop window didn't have focus because the popup window didn't have focus.
Upvotes: 18
Reputation: 4533
Just try:
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();
Upvotes: 47
Reputation: 430
Does the EditText definitely have the android:editable property set to true? If it's false it will be disabled as you describe.
Upvotes: 0