相关疑难解决方法(0)

如何在保留字符状态的情况下向autocompletetextview动态添加建议

问题描述:

我在AutoCompleteTextView面临一些问题,我必须在每次按键后显示建议.事情是,建议列表是动态像谷歌的建议功能.这意味着应该在用户输入时添加新建议,并且应显示所有匹配的旧建议.

例如

我写"te"然后它应该显示以前的建议,如"test1"和"test2"以及我将从Web API获得的新建议.假设web api给了我"茶"和"紧张"的字样.

现在,AutoCompleteTextView将"te"作为字符串,其下方显示所有四个建议.

这正是我要找的.

看起来很简单,但它显示出一种奇怪的行为.

我正在使用我在全局声明的默认ArrayAdapter类实例.

arrayAdapter=new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,suggestions);
word.setAdapter(arrayAdapter);
Run Code Online (Sandbox Code Playgroud)

建议是ArrayList.

从WebApi获得新结果后,我只需致电

arrayAdapter.notifyDataSetChanged();
Run Code Online (Sandbox Code Playgroud)

刷新数据观察者和附加的视图(在我们的例子中是AutoCompleteListView).

但它结束了建议.

当我不使用notifyDataSetChanged();它时,无论我输入的字符是什么,都会显示所有建议.

我尝试使用自定义过滤器,因为我不能使用notifyDataSetChanged(),但没有一个是有用的.

我发布图片以避免混淆.在此输入图像描述

我有一个混乱,为什么notifyDataSetChanged();它不起作用.我没有使用相同的arrayAdapter实例的任何其他列表引用.我真的怀疑这是一个参考问题.

android autocompletetextview notifydatasetchanged android-filterable

11
推荐指数
1
解决办法
8848
查看次数

带有自定义适配器和过滤器的Autocompletetextview

我想设置自定义ArrayAdapter为我AutoCompleteTextView这样的

public class AutoCompleteContactArrayAdapter extends
    ArrayAdapter<Map<String, String>> implements Filterable {
private Context mContext;
private List<Map<String, String>> mContactList;

public AutoCompleteContactArrayAdapter(Context context,
        List<Map<String, String>> objects) {
    super(context, R.layout.auto_contact_list, objects);
    mContext = context;
    mContactList = objects;
    // TODO Auto-generated constructor stub
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.auto_contact_list, parent,
            false);
    TextView nameView = (TextView) rowView.findViewById(R.id.ccontName);
    TextView phoneView = (TextView) rowView.findViewById(R.id.ccontNo);
    TextView typeView = (TextView) rowView.findViewById(R.id.ccontType); …
Run Code Online (Sandbox Code Playgroud)

android

9
推荐指数
2
解决办法
4万
查看次数