AutoCompleteTextView 不适用于自定义 ArrayAdapter

AutoCompleteTextView does not work with custom ArrayAdapter

我正在尝试实现 AutoCompleteTextView 来显示自定义对象。因此我实现了自己的 ArrayAdapter,但它不起作用,当我在文本字段中输入内容时没有显示任何建议。有人可以帮助我吗?

public class AutoCompleteArrayAdapter extends ArrayAdapter<Object>{

    List<Object> mObjectList;
    Context mContext;
    LayoutInflater mInflater;
    int mResourceId;

    public AutoCompleteArrayAdapter(Context context, int resource, List<Object> objectList) {
        super(context, resource, objectList);
        mResourceId = resource;
        mObjectList = objectList;
        mContext = context;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        if(convertView == null) {
            convertView = mInflater.inflate(mResourceId, parent, false);
        }

        Object object = mObjectList.get(position);

        TextView textViewItem = (TextView) convertView.findViewById(R.id.textView_dropDown);
        textViewItem.setText(object.getString());

        return convertView;
    }

    @Override
    public int getCount() {
        return mObjectList.size();
    }

    @Override
    public WordInfo getItem(int position) {
        return mObjectList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}

这里我主要设置适配器activity:

    AutoCompleteArrayAdapter adapter = new AutoCompleteArrayAdapter(this, R.layout.simple_textview, mAllWords);
    mAutoEditTextSwedish.setAdapter(adapter);

在您的自定义 ArrayAdapter class 中,您需要覆盖 public Filter getFilter()

我有一个针对以下问题的示例代码,请看一下:

希望对您有所帮助!