0
我做了一個字典應用程序,但我搜索一個詞,例如水,水不顯示第一行。我想過濾水或w建議word.Whats錯我的代碼? ThnksSearchview Recyclerview過濾(不是隨機)
@Override
public boolean onQueryTextChange(String newText) {
newText = newText.toLowerCase();
final ArrayList<DictObjectModel> filteredList = new ArrayList<DictObjectModel>();
for (int i = 0; i < wordcombimelist.size(); i++) {
final String text = wordcombimelist.get(i).toLowerCase();
if (text.contains(newText) && (text.equals(newText))) {
filteredList.add(new DictObjectModel(wordcombimelist.get(i),meancombimelist.get(i)));
}
}
adapter = new CustomAdapter(filteredList);
recyclerView.setAdapter(adapter);
return true;
}
這是不是必然的添加或刪除方法。我使用sqlite數據庫,並embedeed我的數據庫的應用程序。但過濾器不工作。我想列出當用戶按「a」鍵,然後列出一個...字 – KabardianGangster
像我寫早。每次您要更改RecyclerView的內容時,都不應創建新的適配器。在CustomAdapter中創建一個名爲「filter」的方法,或類似於使用DictObjectModel的List的方法,從CustomAdapter中的列表中移除uninscary項並在「filter」方法內調用notifyDataSetChanged。 – ostojan
好thnx我嘗試給你的建議:) – KabardianGangster