Android:带有默认建议的 AutoCompleteTextView [英] Android: AutoCompleteTextView with default suggestions

查看:40
本文介绍了Android:带有默认建议的 AutoCompleteTextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在用户输入任何内容之前显示 AutoCompleteTextView 的一些默认建议?即使创建了一个扩展 AutoCompleteTextView 的自定义类,我也找不到办法做到这一点.

How do I show some default suggestions for AutoCompleteTextView before the user type anything? I cannot find a way to do this even with creating a custom class that extends AutoCompleteTextView.

我想显示常见输入值的建议,以防止用户打字.

I want to show suggestions for common input values to save the user from typing.

有什么建议吗?

推荐答案

你应该子类化 AutoCompleteTextView 并覆盖 enoughToFilter() 以返回 true每时每刻.之后,您可以调用 performFiltering("",0)(这是一个受保护的函数,因此您可以通过类中的公共函数导出此调用).

You should subclass AutoCompleteTextView and override enoughToFilter() to return true all the time. After that you can call performFiltering("",0) (it's a protected function, so you can export this call via a public function in your class).

类似的东西:

public class ContactsAutoCompleteTextView extends AutoCompleteTextView {


    public ContactsAutoCompleteTextView(Context context) {
        super(context);
    }

    public ContactsAutoCompleteTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ContactsAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean enoughToFilter() {
        return true;
    }

    public void temp() {
        performFiltering("",0);
    }
}

这篇关于Android:带有默认建议的 AutoCompleteTextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆