텍스트와 이미지가 모두 포함 된이 Listview가 있습니다. 각 목록 항목에는 네 가지 핵심 요소가 포함되어 있습니다. 스피너에서 선택한 옵션에 따라 세 가지 TextView 중 하나를 사용하여 목록보기를 필터링 할 수 있기를 원합니다. 이것은 내가 지금까지 무엇을했는지 있습니다 :안드로이드의 회 전자를 사용하여 목록보기 필터링
public class LazyVenueAdapter extends BaseAdapter implements Filterable {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
public LazyVenueAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data = d;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.venue_list_item, null);
TextView title = (TextView) vi.findViewById(R.id.venueName);
TextView location = (TextView) vi.findViewById(R.id.venueLocation);
TextView tags = (TextView) vi.findViewById(R.id.venueTags);
ImageView thumb_image = (ImageView) vi.findViewById(R.id.venueImage);
HashMap<String, String> venue = new HashMap<String, String>();
venue = data.get(position);
// Setting all values in listview
title.setText(venue.get(VenuesFragment.KEY_TITLE));
location.setText(venue.get(VenuesFragment.KEY_LOCATION));
tags.setText(venue.get(VenuesFragment.KEY_TAGS));
imageLoader.DisplayImage(venue.get(VenuesFragment.KEY_THUMB_URL),
thumb_image);
return vi;
}
@Override
public Filter getFilter() {
Filter filter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
ArrayList<HashMap<String, String>> filteredArrayVenues = new ArrayList<HashMap<String, String>>();
data.clear();
if (constraint == null || constraint.length() == 0) {
results.count = data.size();
results.values = data;
} else {
constraint = constraint.toString();
for (int index = 0; index < data.size(); index++) {
HashMap<String, String> dataVenues = data.get(index);
if (dataVenues.get(VenuesFragment.KEY_TAGS).toString().startsWith(
constraint.toString())) {
filteredArrayVenues.add(dataVenues);
}
}
results.count = filteredArrayVenues.size();
System.out.println(results.count);
results.values = filteredArrayVenues;
Log.e("VALUES", results.values.toString());
}
return results;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
data = (ArrayList<HashMap<String, String>>) results.values;
notifyDataSetChanged();
}
};
return filter;
}
}
내가 드롭 다운 목록에서 옵션을 선택하면 내가 다시 빈 결과 집합을 얻을 수 있다는 점이다 데 문제.
전적으로 도움을 주신 귀하의 제안에 진심으로 감사드립니다. 그래도 작동하려면 한 가지 더해야했습니다. TAGS ** startswith() **를 확인하고 ** contains() **를 사용하는 대신 –
내 제안이 도움이 되었기 때문에 기쁩니다. 올바른 답을 확인해주십시오. 커뮤니티에서 질문이 해결되었음을 알리고 응답자에게 평판을 바칩니다. (가장 좋은 답변은 거의 완벽하지 않으며 가장 생산적인 응답을 선택하십시오.) – Sam