在Android的动态更新自动完成框?自动完成、动态、Android

由网友(殇ベ)分享简介:我会想知道,如果我们能不断地调用一些服务,为获取结果,并显示在自动完成列表。I will like to know if we can continuously call some service for fetching results and displaying in Autocomplete list.我有...

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

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.

阅读全文

相关推荐

最新文章