我正在使用SearchView
而我的活动正在浏览 Sherlock Library。
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// TODO Auto-generated method stub
inflater.inflate(R.menu.countriesxml, menu);
SearchView mSearchView = (SearchView) menu.findItem(R.id.searchall)
.getActionView();
mSearchView.setQueryHint("Search for smartphones");
MenuItem menuItem = menu.findItem(R.id.searchall);
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// TODO Auto-generated method stub
item.collapseActionView();
indicator.setVisibility(View.VISIBLE);
pager.setVisibility(View.VISIBLE);
lvth.setVisibility(View.GONE);
return true;
}
});
return;
}
请注意,我尝试使用OnCloseListener(),但它不起作用。
怎么了?
答案 0 :(得分:2)
在本节中查看您的代码:
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
将其替换为以下代码,然后重试。
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return true;
}
答案 1 :(得分:1)
尝试使用OnFocusChangeListener
menuItem.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean queryTextFocused) {
if (!queryTextFocused) {
// Code here
}
}
});