Reputation: 469
I have an EditText which updates a PopupWindow on each keypress. If I create the PopupWIndow with .setFocusable(true), then it grabs focus and I can't keep typing. However, if I use .setFocusable(false), the ListView inside the PopupWindow does not trigger the OnItemClickedListener.
Is it posible create a PopupWindow without it grabbing focus, but still make widgets inside it clickable?
(The PopupWidow is not for autocomplete, so I don't think AutoCompleteTextView is what I need)
Upvotes: 5
Views: 3293
Reputation: 1457
I guess you can use ListPopupWindow. It handle some focus issues for you. Here is a very simple code. It still has to add more listeners to fit your need. But it figures focus issues out.
ListPopupWindow popup;
EditText editText;
String[] strAry = {"a", "2", "3", "4", "5", "6", "7", "8", "9"};
editText=(EditText)this.findViewById(R.id.editText);
popup= new ListPopupWindow(this.getApplicationContext());
popup.setAdapter(new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1,strAry));
popup.setAnchorView(editText);
popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
editText.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View eventView) {
if(!popup.isShowing()){
popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
popup.show();
}
}
});
editText.addTextChangedListener(new s(){
@Override
public void afterTextChanged(Editable arg0) {}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
if(!popup.isShowing()){
popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
popup.postShow();
}
}
});
Upvotes: 3