gpt4 book ai didi

java - 如何在Android中实现SearchView

转载 作者:行者123 更新时间:2023-12-01 09:44:35 24 4
gpt4 key购买 nike

我创建了一个SearchActivity基于RecyclerView应该搜索 ArrayList<>我已在我的 MainActivity 中声明过

public class SearchActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handleIntent(getIntent());
}

public void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}

public void onListItemClick(ListView l, View v, int position, long id) {
//DA IMPLEMENTARE: chiama accordo activity
// do not care about this method, I'll implement it later
}

private void handleIntent(Intent intent) {
if(Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doSearch(query);
}
}

private void doSearch(String queryStr) {
// I think I should implement an adapter here
}

}

我想我应该在doSearch()中实现一些东西方法,但不知道怎么做。如果您能帮助我,我将不胜感激

最佳答案

您应该使用过滤器并在 RecyclerView 适配器上实现 Filterable。检查这个link出去。或检查此 tutorials如果你不想使用Filter方法

关于java - 如何在Android中实现SearchView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38170730/

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