1

I have a SearchView that is being always shown and a TabHost above as follows:

SearchView on top ("žodis"), TabHost above ("English", "Lietuvių")

I'm trying to keep SearchView focused on certain conditions by doing:

searchView.setIconified(false);
searchView.requestFocusFromTouch();

when I need focus. It seems to work fine.

However, if user switches tabs, refocusing SearchBar in TabHost.OnTabChangeListener doesn't seem to work properly - keyboard is still being shown as if SearchView was still focused, but the cursor on search view is gone and user can't type anything in. Tapping on a search view fixes things but I would like to do the "tap" myself instead of the user.

How do I re-focus search view properly?

Linas Valiukas
  • 1,316
  • 1
  • 13
  • 23

1 Answers1

0

I ended up refocusing SearchView after a delay to allow the UI to finish updating (on mobile, sorry for brevity and typos):

tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {   
    @Override public void onTabChanged(String tabId) {
        searchView.postDelayed(new Runnable() {
            @Override public void run() {
                searchView.setIconified(false);
                searchView.requestFocusFromTouch();
            }
        }, 100);
    }
});
Linas Valiukas
  • 1,316
  • 1
  • 13
  • 23