gpt4 book ai didi

android - 如何处理android中搜索 View 的后退按钮

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

我开发了一个在操作栏中有搜索 View 的应用程序,当我完美地搜索它的过滤器时我遇到了问题但是当我按下后退按钮时它仍然显示过滤器数据所以我的问题是后退按钮的事件是什么操作栏搜索 View 。?

enter image description here

我的搜索 View 代码是

SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(Menus.SEARCH));
searchView.setQueryHint(this.getString(R.string.search));
editSearch = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
editSearch.setHintTextColor(getResources().getColor(R.color.white));
searchView.setOnQueryTextListener(OnQuerySearchView);


private OnQueryTextListener OnQuerySearchView = new OnQueryTextListener() {

@Override
public boolean onQueryTextSubmit(String newText) {
if (TextUtils.isEmpty(newText)) {
listAllContact.clearTextFilter();
} else {
listAllContact.setFilterText(newText.toString());
}
return true;
}

@Override
public boolean onQueryTextChange(String newText) {
String text = editSearch.getText().toString()
.toLowerCase(Locale.getDefault());
adapter.filter(text);
return true;
}

};

适配器中的过滤方法

public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
propertyList.clear();

if (charText.length() == 0) {
propertyList.addAll(arrayList);
notifyDataSetChanged();

} else {
for (ContactProperty p : arrayList) {
if (p.getFriendName().toLowerCase(Locale.getDefault())
.contains(charText)) {
propertyList.add(p);
}
}
notifyDataSetChanged();

}

最佳答案

您可以为此添加监听器:

MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
searchMenuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// Do whatever you need
return true; // KEEP IT TO TRUE OR IT DOESN'T OPEN !!
}

@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do whatever you need
return true; // OR FALSE IF YOU DIDN'T WANT IT TO CLOSE!
}
});

关于android - 如何处理android中搜索 View 的后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24759502/

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