答案 0 :(得分:1)
此代码可帮助您搜索列表
edPeopleSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
edPeopleSearch.setCursorVisible(true);
if (list != null) {
s = s.toString().toLowerCase();
final ArrayList<PagePeopleModel> filter_list = new ArrayList<PagePeopleModel>();
for (int i = 0; i < list.size(); i++) {
final String text = list.get(i).getFirst_name().toLowerCase() + list.get(i).getLast_name().toLowerCase();
if (text.contains(s)) {
filter_list.add(list.get(i));
}
}
adapter = new PagePeopleAdapter(activity, filter_list);
resViewPeopleCode.setAdapter(adapter);
adapter.notifyDataSetChanged();
if (s.length() > 0) {
imgPagePeopleClose.setVisibility(View.VISIBLE);
} else {
imgPagePeopleClose.setVisibility(View.GONE);
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});