gpt4 book ai didi

Android ActionBarSherlock,SearchView `setOnCloseListener` 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:00:36 24 4
gpt4 key购买 nike

我正在使用 SearchView,它工作正常,但只有 setOnCloseListener 不工作;这是我的代码

import com.actionbarsherlock.widget.SearchView.OnCloseListener;

searchView.setOnCloseListener(new OnCloseListener() {
@Override
public boolean onClose() {

Toast.makeText(context, "close", Toast.LENGTH_SHORT).show();
return false;
}
});

**编辑****

@Override
public boolean onCreateOptionsMenu(Menu menu) {
//Used to put dark icons on light action bar
//Create the search view
final SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
searchView.setQueryHint("Search");
searchView.setIconifiedByDefault(true);

//search button
menu.add(Menu.NONE,Menu.NONE,1,"Search a word")
.setIcon(R.drawable.abs__ic_search_api_holo_light)
.setActionView(searchView)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

MenuItem sView = menu.findItem(1);

sView.setOnActionExpandListener(this);

return true;

}

@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
adopter.getFilter().filter(null);
Toast.makeText(getApplicationContext(), "collapse", Toast.LENGTH_LONG).show();
return true; // Return true to collapse action view
}

@Override
public boolean onMenuItemActionExpand(MenuItem item) {
Toast.makeText(getApplicationContext(), "Expand", Toast.LENGTH_LONG).show();
return true; // Return true to expand action view
}

最佳答案

自己解决了。只留下 setOnCloseListener 它不会起作用,并将以下代码放在 onCreateOptionsMenu

//        searchView.setOnCloseListener(new OnCloseListener() { 
// @Override
// public boolean onClose() {
// adapter.getFilter().filter("");
// Toast.makeText(getBaseContext(), "on close", Toast.LENGTH_SHORT).show();
// return false;
// }
// });

MenuItem menuItem = menu.findItem(ID_OF_SEARCHVIEW);
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
adapter.getFilter().filter("");
return true;
}

@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
adapter.getFilter().filter("");
return true;
}
});

关于Android ActionBarSherlock,SearchView `setOnCloseListener` 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15459882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com