Search suggestions from network resource into Quick Search box

后端 未结 3 1972
孤城傲影
孤城傲影 2020-12-08 05:24

I\'m building the search in an application and need to have a way of putting the suggestions which I get from my server as a JSON-array into the list of suggestions which is

3条回答
  •  春和景丽
    2020-12-08 05:57

    Found the solution on developer.android.com:

    If you have suggestions that you get from a network location, you can build a cursor on the fly when you get the results from your server.

    This goes inside your ContentProvider's query() method:

    String[] columns = {
       BaseColumns._ID, 
       SearchManager.SUGGEST_COLUMN_TEXT_1, 
       SearchManager.SUGGEST_COLUMN_INTENT_DATA
    };
    
    MatrixCursor cursor = new MatrixCursor(columns);
    
    for (int i = 0; i < arr.length(); i++)
    {
      String[] tmp = {Integer.toString(i), arr.getString(i), arr.getString(i)};
      cursor.addRow(tmp);
    }
    return cursor;
    

    The cursor is the used in the quick-search box to fill a list of suggestions.

提交回复
热议问题