如何搜索仅以“b”开头的单词在Android的listview中从apple,an,bool,abc,abort,boll,god,good等? [英] how to search word which only starts with "b" from apple, an , bool,abc, abort, boll, god , good etc in listview in Android?
问题描述
我正在使用sqlite DB做一个Android项目,并且能够在listview中填充列表。
我还可以使用以下代码搜索listview中的单词:
I am doing one Android project using sqlite DB and was able to populated the lists in listview.
I was also able to search the words in listview using following codes:
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
MainActivity.this.myAdapter.getFilter().filter(s);
或
or
@Override
public boolean onQueryTextChange(String newText) {
// myAdapter.getFilter().filter(newText );
if (TextUtils.isEmpty(newText)) {
lvUsers.clearTextFilter();
} else {
lvUsers.setFilterText(newText.toString());
}
return true;
}
但我得到的是与listview中输入的字符串相关的随机单词,假设我有像苹果这样的单词,an,bool,abc,abort,boll,god,good等所以当我输入bEditText或searchview时,我只需要bool,boll。但是现在我得到bool,abc,abort和boll等等。
因此,你的帮助最受欢迎。谢谢你
but i am getting random words which is related to the entered string from listview, suppose i have words like apple, an , bool,abc, abort, boll, god , good etc. So i need to get only "bool", "boll" while i enter "b" EditText or searchview. but now i am getting bool,abc,abort and boll so on.
therefore, your kind helps are most appreciated.Thank You
推荐答案
可以通过检查从数据库获得的单词内的类型字符串的索引来完成。按照我的解决方案 -
根据android中的名称过滤Listview [ ^ ]
It can be done by checking the index of the typed string inside the word you get from database. Follow my solution here-
Filtering Listview according to name in android[^]
这篇关于如何搜索仅以“b”开头的单词在Android的listview中从apple,an,bool,abc,abort,boll,god,good等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!