Dynamically update autocomplete field in Android?

I would like to know if we can constantly call some services to get results and display them in the autocomplete list.

I have one screen with a text field, and when the user starts typing in this text field, autocomplete should be filled with data. Data will not be hardcoded and will be received via an http connection. I think I need to call an http connection in the onTextChanged Edittext method, but this is the perfect solution.

In addition, if this type of implementation is performed in a mobile application. Since this feature works on the Internet. Can this be done in a mobile application?

Is it possible?

+6
android dynamic autocomplete
source share
1 answer

Write a custom SimpleCursorAdapter . Now bind this adapter to your EditText. Here is the code to create the 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 Configuring a cursor adapter . You may need to customize it to suit your requirements.

+2
source share

All Articles