How to handle offer click event with SearchView in ActionBar, ContentProvider, calling webService, returning cursor?

I have a problem when I try to configure automatic search using searchView on an ActionBar.

I have a contentProvider that calls webService on its own to get suggestions. It returns the cursor, and the sentence is correctly presented in the user interface.

The problem is that nothing happens when I select one of these suggestions.

I'm not sure what to store in SUGGEST_COLUMN_INTENT_ACTION.

When reading the documentation, I realized that the onCreate method of my activity must be called again and that I can get SUGGEST_COLUMN_INTENT_ACTION to find out the context and get SUGGEST_COLUMN_INTENT_DATA with the intention .getData ().

OnCreate is never called, no exception is thrown, nothing happens ...

What did I miss? Why does nothing happen when I choose an offer?

My searchable.xml:

<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="@string/search_hint" android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" android:searchSuggestAuthority="MyPackage.search_suggestion_provider" android:searchSuggestIntentAction="android.intent.action.SEARCH" > </searchable> 
+4
source share
1 answer

I just changed setOnClickListener to setOnSuggestionListener and it worked ...

Now I get the position of the proposed offer, but I need the identifier that my provider set in the cursor after the search is completed. I did it like this:

  CursorAdapter c = searchView.getSuggestionsAdapter(); ... Cursor cur = c.getCursor(); cur.move(position); String val = cur.getString(cur.getColumnIndex(BaseColumns._ID)); 

Is this the best way to do this?

Due to the lack of a good tutorial regarding searchView in an actionBar using contentProvider to asynchronously call webService, I'm just trying to get this to work, and I have one more question:

I never create an xml file describing a list that shows my suggestion. How it works? Did you manage to create this listView based on the curosr description returned by my contentProvider?

thanks again.

+5
source

Source: https://habr.com/ru/post/1482981/


All Articles