sun*_*nil 6 android autocomplete dynamic
我想知道我们是否可以不断调用某些服务来获取结果并显示在自动完成列表中.
我有一个带有文本框的屏幕,当用户开始在该文本框中输入时,自动完成应该填充数据.数据不会被硬编码,将通过http连接获取.我想我需要在Edittext的onTextChanged方法中调用http连接,但这是完美的解决方案.
此外,这种类型的实现应该在移动应用程序中完成.因为,这个功能是基于网络的.这可以在移动应用程序中完成吗?
这可行吗?
写一个自定义SimpleCursorAdapter。现在将此适配器关联到您的 EditText。以下是构造 Cursor 对象并返回它的代码:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
这是自定义光标适配器的示例。您可能需要对其进行自定义以满足您的要求。