views:

204

answers:

1

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?

+1  A: 

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.

Ankit Jain
will this work for dynamically. What I mean is the request will not be sent only one first time but it will be sent on every character entered in the edittext. Is that feasible?
sunil
Yes! The method `runQueryOnBackgroundThread` is called for each character pressed.
Ankit Jain