Tôi có tiện ích tìm kiếm đang hoạt động và muốn thêm đề xuất lịch sử tìm kiếm. Tôi đã làm theo hướng dẫn Android (http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html) và trong khi tìm kiếm vẫn hoạt động, không có đề xuất nào được hiển thị. Đây là mã của tôi:Android SearchRecentSuggestions - đề xuất không được hiển thị khi nhập vào SearchView
Content cung cấp
package com.mypackage; import android.content.SearchRecentSuggestionsProvider; public class SearchHistoryProvider extends SearchRecentSuggestionsProvider { public final static String AUTHORITY = SearchHistoryProvider.class.getName(); public final static int MODE = DATABASE_MODE_QUERIES; public SearchHistoryProvider() { setupSuggestions(AUTHORITY, MODE); } }
Tuyên bố cung cấp dịch vụ trong Manifest
<provider android:name=".SearchHistoryProvider" android:authorities="com.mypackage.SearchHistoryProvider"> </provider>
cấu hình Searchable
<?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="com.mypackage.SearchHistoryProvider" android:searchSuggestSelection=" ?"> </searchable>
Tiết kiệm các truy vấn đến các nhà cung cấp nội dung (trong Hoạt động tìm kiếm của tôi)
private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE); suggestions.saveRecentQuery(query, null); // Collapse the search view as a search is performed MenuItem searchItem = mMenu.findItem(R.id.search); SearchView searchView = (SearchView) mMenu.findItem(R.id.search).getActionView(); searchItem.collapseActionView(); searchView.setQuery("", false); // send the query to the global search activity for loading the data Intent globalSearchIntent = new Intent(this, GlobalSearchFragmentActivity.class); GroceryOTGUtils.copyIntentData(intent, globalSearchIntent); globalSearchIntent.putExtra(GlobalSearchFragmentActivity.GLOBAL_SEARCH, true); startActivity(globalSearchIntent); } }
Tất cả mọi thứ hoạt động tốt, ngoại trừ các đề xuất này không thực sự hiển thị (tìm kiếm trông giống như trước chúng tôi được gửi). Mọi sự trợ giúp sẽ rất được trân trọng!
Ah, tôi đã giải quyết được vấn đề. Đó là một sai lầm trong cấu hình tệp kê khai Android (tên của nhà cung cấp). Làm thế nào tôi có thể loại bỏ tiền thưởng? –
@ Eng.Fouad nếu bạn đặt tiền thưởng cho những người khác, bạn không thể loại bỏ tiền thưởng! –
@ Eng.Fouad người kiểm duyệt có thể hoàn trả tiền thưởng trong trường hợp cực đoan, bạn có thể thử và gắn cờ bài đăng này, chọn "Khác" và cầm cố trường hợp của bạn. Vẫn chưa quá muộn. :) –