在Android中动态更新自动完成框? [英] Dynamically update autocomplete box in Android?

查看:19
本文介绍了在Android中动态更新自动完成框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们是否可以连续调用一些服务来获取结果并显示在自动完成列表中.

I will like to know if we can continuously call some service for fetching results and displaying in Autocomplete list.

我有一个带有文本框的屏幕,当用户开始在该文本框中输入时,自动完成应填充数据.数据不会被硬编码,而是通过 http 连接获取.我想我需要在 Edittext 的 onTextChanged 方法中调用 http 连接,但这是完美的解决方案.

I have one screen with the text box and when user starts entering in that textbox the autocomplete should get filled with the data. The data will not be hardcoded and will be fetched through http connection. I think I need to call http connection in onTextChanged method of Edittext but is that the perfect solution.

此外,这种类型的实现是否应该在移动应用程序中完成.因为,此功能是基于 Web 的.这也可以在移动应用程序中完成吗?

Moreover, should this type of implementation done in mobile application. Since, this feature is web based. Can this be done in mobile application too?

这可行吗?

推荐答案

编写自定义 SimpleCursorAdapter.现在将此适配器关联到您的 EditText.下面是构造一个 Cursor 对象并返回它的代码:

Write a custom SimpleCursorAdapter. Now associate this adapter to your EditText. Here is the code to construct a Cursor object and return it:

public class ValueCursorAdapter extends SimpleCursorAdapter implements Filterable
{

    ...
 // overrise the newView() to associate mCursor[1] and mCursor[2] to relevant views within
    ...

    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint)
    {
        MatrixCursor mCursor = new MatrixCursor(new String[] { "_id", "uri", "label" });
        .. // result = ??
            while (result.hasNext())
            {
                mCursor.addRow(new Object[] { count, "uri", "title"});
                count++;
            }
        return mCursor;
    }
}

这是自定义光标适配器的示例.您可能需要对其进行自定义以满足您的要求.

Here is an example for Customizing Cursor Adapter. You might need to customize it to fit your requirements.

这篇关于在Android中动态更新自动完成框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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