添加在自动完成TextView的Andr​​oid的一个永久搜索标题自动完成、标题、Andr、TextView

由网友(小清新的八个字)分享简介:我想补充一个永久的搜索结果在Android的自动填充文本视图。对于例如:如果我进入自动完成X,如果它显示的酒店...... XYZ1,xyz2.etc列表...那么最后的结果必然是不在列表中的价值。如果用户无法找到自己的酒店,那么就可以以列表选择不选择。I want to add a permanent searc...

我想补充一个永久的搜索结果在Android的自动填充文本视图。 对于例如:如果我进入自动完成X,如果它显示的酒店...... XYZ1,xyz2.etc列表...那么最后的结果必然是不在列表中的价值。如果用户无法找到自己的酒店,那么就可以以列表选择不选择。

I want to add a permanent search result in autocomplete text view in android. For ex:If i enter 'x' in the autocomplete and if it shows the list of hotels...xyz1,xyz2.etc...Then the last result must be "NOT IN LIST" value. If the user cant find their hotel then they can select NOT IN LIST option..

即使在文本中的用户类型的predictive搜索不能给那么不在列表中应该是唯一的建议是自动完成的应该给。我是新来的Andr​​oid.I在做一个小app.Plz help..If我必须使用自定义的自动填充文本视图那么,我应该覆盖哪些方法?如果是的话,告诉我一个方法,code,我必须重写

Even if the user types in the text that the predictive search could not give then 'NOT IN LIST' should be the only suggestion that autocomplete should give. I am new to Android.I am doing a small app.Plz help..If i have to use custom autocomplete text view then what method should i override? If so ,tell me with a method code that i have to override

推荐答案

下面是一个 AutoCompleteAdapter 我用我的应用程序之一。我希望这能解决你的问题。

Here is an AutoCompleteAdapter i used in one of my apps. I hope this solves you problem

从下面适配器设置为你的 AutoCompleteTextView 控制:

Set the adapter from below to your AutoCompleteTextView control:

    ArrayAdapter<String> adapter = new AutoCompleteAdapter(this,
            R.layout.dropdown_item);

    autoComplete.setAdapter(adapter);

样品适配器:

Sample adapter:

private class AutoCompleteAdapter extends ArrayAdapter<String>
        implements Filterable {
    private ArrayList<String> mData;

    public AutoCompleteAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
        mData = new ArrayList<String>();
    }

    @Override
    public int getCount() {
        try {
            return mData.size();
        } catch (NullPointerException e) {
            return 0;
        }
    }

    @Override
    public String getItem(int index) {
        return mData.get(index);
    }

    @Override
    public Filter getFilter() {
        Filter myFilter = new Filter() {
            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults filterResults = new FilterResults();
                if (constraint != null) {
                    //This shows a progress to the user in my app. you don't need to use this
                    handle.sendEmptyMessage(MSG_SHOW_PROGRESS);
                    try {
                        //Fill mData with your data
                        mData = XmlParser.searchLocations(constraint
                                .toString());
                    } catch (Exception e) {
                        handle.sendEmptyMessage(MSG_HIDE_PROGRESS);
                    }
                    mData.add("NOT IN LIST");
                    filterResults.values = mData;
                    filterResults.count = mData.size();
                }
                return filterResults;
            }

            @Override
            protected void publishResults(CharSequence contraint,
                    FilterResults results) {
                if (results != null && results.count > 0) {
                    notifyDataSetChanged();
                    handle.sendEmptyMessage(MSG_HIDE_PROGRESS);
                } else {
                    notifyDataSetInvalidated();
                    handle.sendEmptyMessage(MSG_HIDE_PROGRESS);
                }
            }
        };
        return myFilter;
    }
}
阅读全文

相关推荐

最新文章