我显示了listview
来自数据库的数据,现在我想通过提供的关键字(忽略大小写)从列表中搜索特定项目。我试过了,但没有得到预期的结果。按照我所做的代码,它没有给出错误,但也没有达到我的期望。请帮助更进一步。
ArrayList<String> bank=new ArrayList<String>();
EditText inputSearch;
inputSearch.addTextChangedListener(new TextWatcher() {
private ArrayList<String> arrayList_sort = new ArrayList<String>();
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
int textlength=0;
textlength=inputSearch.getText().length();
if(arrayList_sort!=null)
arrayList_sort.clear();
for(int i=20;i<=bank.size();i++)
{
if(textlength<=bank.get(i).toString().length())
{
//if(inputSearch.getText().toString().equalsIgnoreCase(String) bank.get(i).toString().subSequence(0, textlength)))
if (inputSearch
.getText()
.toString()
.equalsIgnoreCase(
(String) bank.get(i).toString()
.subSequence(0, textlength)))
{
arrayList_sort.add(bank.get(i));
Log.d("TAG", "log" + arrayList_sort.size());
}
}
}
}
public void beforeTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
}
我用过BaseAdapter
。IndexOutOfBound
当 i=0 时,它会给出错误“ ”。