0

I have a ListView, each row has a TextView, upon clicking on the row, I want a PopupWindow with an EditText to pop under the row. The text entered by the user should be then displayed in the TextView of the row.

When I click on a row the TextView does appear, but I do not get the on-screen keyboard. But I am using emulator, and whatever I type on my keyboard does appear in the EditText. But I need on-screen keyboard to appear as well obviously. Also, since the EditText never seems to have focus, I can never get rid of it since I am dismissing the PopupWindow when the EditText loses focus.

I have looked at this, this, and a few other answers as well. They all say setFocusable(true) should be done for the PopupWindow. This didn't work. Other answers say dismiss and show the popup again or set a background for the popup, or to explicitly call InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); and displaying soft input, tried all, none work.

Here is my onListItemClick code:

private class SearchItemClickListener implements
    ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            Log.d("listItemClick", "received lsit click");
            final TextView selectTV=(TextView)view.findViewById(R.id.filter_name);
            final StringPair selectItem=mSearchFilters.get(position);

                final PopupWindow mPopupWindow;
                Log.d("listItemClick", "got to else");
                LinearLayout layout=new LinearLayout(mContext);
                final EditText et=new EditText(mContext);
                et.setWidth(LayoutParams.MATCH_PARENT);
                et.setTextColor(Color.BLACK);
                et.setSingleLine();
                et.setBackgroundResource(android.R.drawable.editbox_background_normal);;
                layout.addView(et);
                mPopupWindow=new PopupWindow(layout, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

                et.setOnFocusChangeListener(new OnFocusChangeListener() {

                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if(!hasFocus){
                            selectTV.setText(et.getText().toString());
                            selectItem.second=et.getText().toString();
                            mPopupWindow.dismiss();
                        }

                    }
                });
                mPopupWindow.setFocusable(true);
                mPopupWindow.update();
                mPopupWindow.showAsDropDown(view);
                mPopupWindow.dismiss();
                mPopupWindow.showAsDropDown(view);
                Log.d("listItemClick", "showed popup");

            }


    }

PS On a sidenote, the EditText width is very small, seems to be able to contain only 4-5 characters, how do I get it to be the ful screen width? setting width to MATCH_PARENT doesn't work.

Here is a picture, small edittext and no keyboard:

fail popup

Community
  • 1
  • 1
Kartik_Koro
  • 1,277
  • 1
  • 11
  • 23

1 Answers1

0

You can try

.
.
.
et.setOnFocusChangeListener(new OnFocusChangeListener() {

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
       if(!hasFocus){
            selectTV.setText(et.getText().toString());
            selectItem.second=et.getText().toString();
            mPopupWindow.dismiss();
       }

    }
});
mPopupWindow.showAsDropDown(view);
mPopupWindow.setFocusable(true);
mPopupWindow.update();
.
.
.
Oğuzhan Döngül
  • 7,856
  • 4
  • 38
  • 52
  • Remove that part mPopupWindow.showAsDropDown(view); mPopupWindow.dismiss(); mPopupWindow.showAsDropDown(view); – Oğuzhan Döngül Jun 30 '14 at 08:25
  • Then Try these links http://stackoverflow.com/questions/6977773/keyboard-not-shown-when-i-click-on-edittextview-in-android http://stackoverflow.com/questions/21793908/edittext-in-popupwindow-not-showing-keyboard-even-if-setfocusabletrue – Oğuzhan Döngül Jun 30 '14 at 08:47