I will like to know if we can continuously 开发者_如何学运维call some service for fetching results and displaying in Autocomplete list.
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?
Is this feasible?
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.
精彩评论