0

I am trying to use the SearchWidget Action bar functionality using a custom set of data. The problem is when i enter any character in the search bar the suggestion ui is empty. From the log I see that the ContentProvider is used. I dont however see any log from the "Searchable Activity".

@Override
public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
    // TODO: Implement this to handle query requests from clients.
    String query = uri.getLastPathSegment().toLowerCase();
    Log.d("app", "AAAAAAAAAAAAA "+query);

    String[] columnNames = {"_id", "Column1"};
    MatrixCursor matrixCursor = new MatrixCursor(columnNames);
    matrixCursor.addRow(new String[]{"1a", "r1v1"});
    matrixCursor.addRow(new String[]{"2a", "r2v1"});

    return matrixCursor;
    //adapter.swapCursor(matrixCursor);
    //throw new UnsupportedOperationException("Not yet implemented");
}

My SearchableActivity has following:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_searchable);
    Log.d("app", "NNNNNNNNNNNNNN");
    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        // Handle a suggestions click (because the suggestions all use ACTION_VIEW)
        Uri data = intent.getData();
    }
}

I guess I am missing some very simple steps to connect some dots and display the results. Can anyone help?

user1647708
  • 447
  • 3
  • 9
  • 22
  • 1
    why dont you use searchView.setSuggestionsAdapter() ? – pskink Mar 15 '15 at 14:31
  • @pskink That worked. I used another example of yours http://stackoverflow.com/questions/11628172/converting-an-arrayadapter-to-cursoradapter-for-use-in-a-searchview . – user1647708 Mar 16 '15 at 12:44
  • @pskink i have another question if you dont mind answering related to this. I have a content provider which provides the cursor but i am getting confused on how to connect the cursor from content provider to searchView.setSuggestionsAdapter(cursorAdapter); which is defined in the activity? how do i get cursorAdapter to set it to? – user1647708 Mar 16 '15 at 12:58
  • if you want to use a ContentProvider then follow the standard way of using a SearchView – pskink Mar 16 '15 at 13:04

0 Answers0