Dynamically update autocomplete box in Android?

后端 未结 1 1660
野性不改
野性不改 2021-01-02 23:01

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 u

相关标签:
1条回答
  • 2021-01-02 23:46

    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.

    0 讨论(0)
提交回复
热议问题