Making Selecting a search suggestion fill search field (#169)

This commit is contained in:
Don Kimberlin 2020-06-18 23:32:26 -07:00 committed by GitHub
parent 7038437d05
commit 18fd3a2384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.SearchRecentSuggestions; import android.provider.SearchRecentSuggestions;
@ -166,7 +167,27 @@ public class VideoListActivity extends CommonActivity {
Log.d(TAG, "onDismiss: "); Log.d(TAG, "onDismiss: ");
loadVideos(0, count, sort, filter); loadVideos(0, count, sort, filter);
}); });
searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
@Override
public boolean onSuggestionClick(int position) {
String suggestion = getSuggestion(position);
searchView.setQuery(suggestion, true);
return true;
}
private String getSuggestion(int position) {
Cursor cursor = (Cursor) searchView.getSuggestionsAdapter().getItem(
position);
return cursor.getString(cursor
.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
}
@Override
public boolean onSuggestionSelect(int position) {
/* Required to implement */
return true;
}
});
return true; return true;
} }