AutoCompleteTextView中的弹出框实现模糊查询
只需重写AutoCompleteTextView中的arrayadapter 重写
Arrayadapter 源码中的words[k].startsWith(prefixString) 修改成 words[k].indexOf(prefixString)!= -1
这里直接复制源码修改(这个可能是老版的源码,具体哪个版本的忘了),之后直接使用这个adapter就行了:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import android.widget.Toast;
public class SearchPupItenAdapter<T> extends BaseAdapter implements Filterable {
/**
* Contains the list of objects that represent the data of this
* ArrayAdapter. The content of this list is referred to as "the array" in
* the documentation.
*/
private List<T> mObjects;
/**
* Lock used to modify the content of {
@link #mObjects}. Any write operation
* performed on the array should be synchronized on this lock. This lock is
* also used by the filter (see {
@link #getFilter()} to make a synchronized
* copy of the original array of data.
*/
private final Object mLock = new Object();
/**
* The resource indicating what views to inflate to display the content of
* this array adapter.
*/
private int mResource;
/**
* The resource indicating what views to inflate to display the content of
* this array adapter in a drop down widget.
*/
private int mDropDownResource;
/**
* If the inflated resource is not a TextView, {
@link #mFieldId} is used to
* find a TextView inside the inflated views hierarchy. This field must
* contain the identifier that matches the one defined in the resource file.
*/
private int mFieldId = 0;
/**
* Indicates whether or not {
@link #notifyDataSetChanged()} must be called
* whenever {
@link #mObjects} is modified.
*/
private boolean mNotifyOnChange = true;
private Context mContext;
// A copy of the original mObjects array, initialized from and then used
// instead as soon as
// the mFilter ArrayFilter is used. mObjects will then only contain the
// filtered values.
private ArrayList<T> mOriginalValues;
private ArrayFilter mFilter;
private LayoutInflater mInflater;
/**
* Constructor
*
* @param context
* The current context.
* @param resource
* The resource ID for a layout file containing a TextView to use
* when instantiating views.
*/
public SearchPupItenAdapter(Context context, int resource) {
init(context, resource, 0, new ArrayList<T>());
}
/**
* Constructor
*
* @param context
* The current context.
* @param resource
* The resource ID for a layout file containing a layout to use
* when instantiating views.
* @param textViewResourceId