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

查看:146
本文介绍了在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.

此外,这种类型的实现应该在移动应用程序中完成。既然,这个功能是基于网络的。这可以在移动应用程序中完成吗?

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