Reputation: 355
I am using SearchView
from Support Library in my Appcombat Actionbar.
On emulator it all works as intended. I can open it by clicking the menu item or using the Search Button on the device and the keyboard is shown.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_SEARCH) {
if(!MenuItemCompat.isActionViewExpanded(searchItem)) {
MenuItemCompat.expandActionView(searchItem);
} else MenuItemCompat.collapseActionView(searchItem);
}
return super.onKeyDown(keyCode, event);
}
On Expanding I set a saved text.
MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener(){
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
searchView.onActionViewExpanded(); // to initialize searchview
searchView.setQuery(searchText, false);
searchView.requestFocus();
return true;
}
});
Problem:
On my hardware device (HTC Desire HD, Android 2.3), when I press the device's Search Button the searchview expands and the softkeyboard shows for a part of a second and hides again. Clicking the MenuItem works fine and shows the keyboard as intended. There seems to be a method hiding the keyboard again after focusing the searchview. I already tried several stuff (setOnQueryTextFocusChangeListener
with manually showing softInput) but none seem to work on my device.
I hope someone got a solution. Thanks
Upvotes: 0
Views: 517
Reputation: 51
It looks like your searchView has lost focus after setting the searchText. try adding this before calling requestFocus.
searchView.setFocusable(true);
Upvotes: 1