使用ArrayAdapter在Android中自定义过滤
我正在尝试过滤使用此ArrayAdapter填充的ListView:
package me.alxandr.android.mymir.adapters;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.Set;import me.alxandr.android.mymir.R;import me.alxandr.android.mymir.model.Manga;import android.content.Context;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.ArrayAdapter;import android.widget.Filter;import android.widget.SectionIndexer;import android.widget.TextView;public class MangaListAdapter extends ArrayAdapter<Manga> implements SectionIndexer{ public ArrayList<Manga> items; public ArrayList<Manga> filtered; private Context context; private HashMap<String, Integer> alphaIndexer; private String[] sections = new String[0]; private Filter filter; private boolean enableSections; public MangaListAdapter(Context context, int textViewResourceId, ArrayList<Manga> items, boolean enableSections) { super(context, textViewResourceId, items); this.filtered = items; this.items = filtered; this.context = context; this.filter = new MangaNameFilter(); this.enableSections = enableSections; if(enableSections) { alphaIndexer = new HashMap<String, Integer>(); for(int i = items.size() - 1; i >= 0; i--) { Manga element = items.get(i); String firstChar = element.getName().substring(0, 1).toUpperCase(); if(firstChar.charAt(0) > 'Z' || firstChar.charAt(0) < 'A') firstChar = "@"; alphaIndexer.put(firstChar, i); } } }
但是,当我在过滤器上调用filter('test')时根本没有任何事情发生(或者运行后台线程,但是只要用户认可,列表就不会被过滤)。我怎样才能解决这个问题?
有只小跳蛙
相关分类