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

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

问题描述

我会想知道,如果我们能不断地调用一些服务,为获取结果,并显示在自动完成列表。

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

我有一个屏幕,文本框,当用户开始输入在文本框自动完成应该得到填充数据。这些数据将不会很难codeD,并通过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。这里是code构建一个游标对象并返回它:

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天全站免登陆