AutoCompleteTextView不显示任何下拉列表

时间:2014-08-09 15:47:21

标签: android autocompletetextview

我尝试使用自定义适配器实现AutoCompleteTextView,但它没有向我显示建议列表。

这是我的活动片段:

Member newMember = new Member();
newMember.setMemberID(1);
newMember.setMemberName("TEST 1");
mAllMemberList.add(newMember);
newMember = new Member();
newMember.setMemberID(2);
newMember.setMemberName("TEST 2");
mAllMemberList.add(newMember);

mMemberInputField = (AutoCompleteTextView) findViewById(R.id.memberInputField);
mAllMemberListAdapter = new MemberInputListAdapter(this, mAllMemberList);
mMemberInputField.setAdapter(mAllMemberListAdapter);

MemberInputListAdapter.java

public class MemberInputListAdapter extends ArrayAdapter<Member> {
    private Context mContext;
    private ArrayList<Member> mMembers = new ArrayList<Member>();

    public GroupMemberInputListAdapter(Context context, ArrayList<Member>members) {
        super(context, R.layout.all_member_listview_item, members);
        mContext = context;
        mMembers = members;
    }

    @Override
    public View getView(final int rowPosition, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.all_member_listview_item, parent, false);          
        return rowView;
    }
}

Member.java

public class Member implements Serializable{
    private int memberID;
    private String memberName;

    public int getMemberID() {
        return memberID;
    }
    public void setMemberID(int memberID) {
        this.memberID = memberID;
    }
    public String getMemberName() {
        return memberName;
    }
    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    @Override
    public String toString() {
        return memberName;
    }
}

当我开始输入&#34; Tes&#34;?

时,我怀疑我的AutoCompleteTextView没有显示任何内容

1 个答案:

答案 0 :(得分:0)

您的自定义ArrayAdapter应实现Filterable接口 您可以查看this example