gpt4 book ai didi

android - 使用 EditText Android 过滤 Json Listview

转载 作者:行者123 更新时间:2023-11-29 01:08:44 26 4
gpt4 key购买 nike

试图用 edittext 过滤我的 ListView ,每次我输入一些文本时 ListView 变成空白,谁能告诉我我做错了什么以及我该如何解决这个问题

search.addTextChangedListener(new TextWatcher (){
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub

}

public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub

}

public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub



String searchString = cs.toString();//wsSearch.getText().toString();
/* if(searchString.length() != 2) {
adapter2 = new Adapter(MainActivity.this, array);
listView.setAdapter(adapter2);
return;
}*/
for (int i = 0; i < array.size(); i++)
{
String currentString = array.get(i).getTitulo();
if (searchString.equalsIgnoreCase(currentString))
{
mTemp.add(array.get(i));
}
}
adapter2 = new Adapter(MainActivity.this, mTemp);
listView.setAdapter(adapter2);

}



});
}

最佳答案

试试这个:

    search.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
String searchString = arg0.toString();//wsSearch.getText().toString();
/* if(searchString.length() != 2) {
adapter2 = new Adapter(MainActivity.this, array);
listView.setAdapter(adapter2);
return;
}*/
mTemp.clear()
for (int i = 0; i < array.size(); i++)
{
String currentString = array.get(i).getTitulo();
if (currentString.contains(searchString))
{
mTemp.add(array.get(i));
}
}
adapter2 = new Adapter(MainActivity.this, mTemp);
listView.setAdapter(adapter2);

}

public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub

}

public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
//BAPTISMAL_SONG.this.adapter2.getFilter().filter(cs);




}



});

希望这对您有所帮助。

关于android - 使用 EditText Android 过滤 Json Listview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44987990/

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