I'm using ActionBarCompat and QuickAction (https://github.com/lorensiuswlt/NewQuickAction also shown at http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/) in my Android app.
In the right of the action bar there's the traditional search icon, user touches it, the search view expands and the user can type the queries.
I have a requirement that, instead of showing recent searches, the popup will show two items “search TYPED_TEXT in foo” and “search TYPED_TEXT in bar”, so, instead of using the default search pop up (so I won't have to deal with content providers and mock a cursor just to show the same two items).
in my SearchView.OnQueryTextListener
, the onQueryTextChange
is overriden so when user types at least 3 chars I set up the QuickAction and show it.
SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
Context context = MyActivity.this.getBaseContext();
LayoutInflater inflator = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = inflator.inflate(R.layout.quickaction_popup, null);
rootView.measure(0, 0);
QuickActionList action = new QuickActionList(MyActivity.this,
QuickActionList.HORIZONTAL, new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
action.addActionView(rootView);
action.show(mSearchView);
// [1]. I'll explain this comment line below.
return false; // I tried with return true as well to indicate I've consumed the event here.
}
}
The problem is: after the quick action is shown, I can't type anything. I must touch the search view again to type another char.
Where I commented with // [1]
, I tried to change focus with setFocusable
+ requestFocus
, setFocusableInTouchMode
+ requestFocus
and even setFocusable
+ setFocusableInTouchMode
+ requestFocus
, but no success at all.
Here's the snippet that replaced // [1]
:
mSearchView.setFocusable(true);
mSearchView.setFocusableInTouchMode(true);
boolean gotFocus = mSearchView.requestFocus();
Log.d("DOUG", Boolean.toString(gotFocus));
Log shows gotFocus = true
, but I still can't type. I see a blue bar showing it's ready to take input, but it's not blinking. Soft keyboard keeps showing as well, but when I type, it's like I'm typing on something not editable. Probably the QuickAction is capturing the soft key event, but I couldn't find how to avoid this.
Any ideas on how to solve this or a workaround?
Thanks
I ended up modifying PopupWindows.java inside NewQuickAction so that
preShow
optionally accepts a parameter to tell if the popup window is focusable. Then it passes the parameter tomWindow.setFocusable(…)
.