0

I'm trying to emulate a software keyboard for a domain specific input. I'm using a PopupWindow to gather the input and transfer it to the underlying EditText. Unfortunately, the PopupWindow is modal, so the user cannot switch from one EditText to another as they can with the usual software keyboard. I've looked into setting the FLAG_NOT_TOUCH_MODAL flag, but I'm not sure when or to what it should be applied to get the behavior I'm looking for.

My code for launching the PopupWindow looks like:

myEdit.setOnClickListener(new View.OnClickListener() {
   public void onClick(View v) {
      pw = myKeyboard.getPopupWindow((EditText) v);

      pw.showAtLocation(Main.this.findViewById(R.id.main), Gravity.BOTTOM, 0, 0);
   }
});

I tried changing it to the following, but this only resulted in the runtime exception: java.lang.RuntimeException: view android.widget.LinearLayout@40526268 being added, but it already has a parent

myEdit.setOnClickListener(new View.OnClickListener() {
   public void onClick(View v) {
      pw = myKeyboard.getPopupWindow((EditText) v);

      WindowManager.LayoutParams wlp = getWindow().getAttributes();
      wlp.gravity = Gravity.BOTTOM;
      wlp.flags = wlp.flags | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
      getWindow().addContentView(pw.getContentView(), wlp);

      pw.showAtLocation(Main.this.findViewById(R.id.main), Gravity.BOTTOM, 0, 0);
  }
});

I'm also looking into setOutsideTouchable, but so far I haven't gotten anywhere.

Any pointers on how I can create a modeless PopupWindow? I would be willing to use some other modeless widget.

Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
Andrew Prock
  • 6,900
  • 6
  • 40
  • 60
  • I ended up going with a slightly different approach. That approach was discussed in this question: http://stackoverflow.com/questions/10309927/update-views-in-one-activity-from-another – Andrew Prock Jan 17 '13 at 18:50

1 Answers1

0

A PopupWindow seems a bit heavy for what you're trying to do, and as you're finding out you're having to fight against it to do what you want. Why not just implement your keyboard as a View and stick it in your layout, then hide/show it?

Christopher Perry
  • 38,891
  • 43
  • 145
  • 187
  • Design aesthetics dictates that the software keyboard behave in as parallel manner to the built in keyboard. I considered hide/show, and if I can find nothing that works, that's what I'll have to do. Given that the android keyboard is modeless, I'd rather pursue that route first. – Andrew Prock Apr 25 '12 at 00:53