1

Possible Duplicate:
PopupWindow not triggering sytem context dialog on EditText long-press

Before I ask this question, I have already spent several hours searching and trying different methods with no luck, it is exactly the same question as this one, which was unanswered, I don't intend to duplicate the question, but I am shocked that this problem is not solved and recorded in SO, cause this requirement is quite common.

This problem is 100% reproducible, simply by creating a PopupWindow with layout that contains an EditText, and long-pressing the EditText, the system edit Dialog does't show up, I know it is a Dialog because of the way it is presented. I am not sure whether it is bug or there are some switches I need to turn on to make EditText work properly in a PopupWindow.

In layout/popupwindow.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#ffffff" >

    <EditText android:id="@+id/etText" android:layout_width="fill_parent" android:layout_height="wrap_content" />

</LinearLayout>

In Activity:

PopupWindow pw = new PopupWindow(getLayoutInflater().inflate(R.layout.popupwindow, null), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
pw.setFocusable(true);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0);

Any ideas?

Community
  • 1
  • 1
neevek
  • 11,760
  • 8
  • 55
  • 73

1 Answers1

1

I give up using PopupWindow, and use Dialog instead, after some tests, I found Dialog is far better than PopupWindow, there are quite a few problems with PopupWindow:

  1. A WebView in PopupWindow does not respond to long press on some versions of Android, and if does, it crashes. this is not a WebView problem but a PopupWindow problem.
  2. An EditText in PopupWindow will shrink its height a little bit when the PopupWindow and the keyboard is first shown and than expand to its original height.
  3. A WebView in PopupWindow loads a page, which contains a text input, and if the text input has the focus, there's no way to intercept the BACK key.
  4. Many others...

Now I use Dialog as container for the WebView, all the mentioned problems disappeared, only there's still a small problem that need to be solved. On ICS, when a dialog is shown, and I press the HOME key, and back to the app, the dialog is hidden, I can't bring the dialog back with Dialog.show(), besides this one, everything is working fine. And I swear I will never use PopupWindow again, PopupWindow sucks!

neevek
  • 11,760
  • 8
  • 55
  • 73