안드로이드에서 목록보기로 검색하려고합니다. 내가 텍스트를 입력 할 때 여기 내 코드안드로이드 검색에서 검색 필터보기
@Override
public Filter getFilter(){
return new Filter(){
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults result = new FilterResults();
if (constraint != null && constraint.toString().length() > 0) {
constraint = constraint.toString();
List<FoodCell> founded = new ArrayList<FoodCell>();
for(FoodCell item: allItemFood){
if(item.cellText.toString().contains(constraint)){
founded.add(item);
}
}
result.values = founded;
result.count = founded.size();
}else
result.count = 0;
return result;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
clear();
if(results.count != 0){
for (FoodCell item : (List<FoodCell>) results.values) {
add(item);
}
}
notifyDataSetChanged();
}
};
}
@Override
public boolean onQueryTextChange(String newText) {
//check if user deleted a character
if(length > newText.length()){
allItemFood = allItemFoodTmp;
}
if (TextUtils.isEmpty(newText)) {
adapter = new CustomListViewAdapter(this, R.layout.listfood,allItemFood);
getListView().setAdapter(adapter);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
} else {
adapter.getFilter().filter(newText);
}
length = newText.length();
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
우리가 목록에서 다음 항목이 있다고 가정하고, AA는, AB, AC 는 "AAZ는"검색 쿼리로, 그것은 사실이다하지만 빈 목록을 보여줍니다 난 문자를 삭제하는 경우 검색 쿼리에서 "z"를 입력하면 결과는 비어 있으며 결과는 예상대로 false입니다. 어떻게 해결할 수 있습니까?
전체 어댑터 게시 – Blackbelt
유용하지 않으며, 클릭 동작을위한 코드가 포함되어 있습니다. –