我的应用程序SearchView
有自定义搜索建议提供程序。建议显示得很好,但建议名称是硬编码的。我想从我的strings.xml
文件中获取本地化字符串,但我需要访问我在搜索提供程序中没有的活动上下文。
我的搜索提供程序使用Android Developer docs中建议的SearchView
文件映射到我的searchables.xml
。这是我的可搜索配置:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="artist, track informations..."
android:label="@string/app_name"
android:queryAfterZeroResults="true"
android:searchSuggestAuthority="com.example.testapp.providers.QuickSearchProvider"
android:searchSuggestSelection=" ?"
android:searchSuggestThreshold="3" />
......这是实际的搜索提供商:
public class QuickSearchProvider extends SearchRecentSuggestionsProvider {
public final static String AUTHORITY = "com.example.testapp.providers.QuickSearchProvider";
public final static int MODE = DATABASE_MODE_QUERIES | DATABASE_MODE_2LINES;
public QuickSearchProvider() {
setupSuggestions(AUTHORITY, MODE);
}
public Cursor query(Uri uri, String[] projection, String sel,
String[] selArgs, String sortOrder) {
MatrixCursor cursor = new MatrixCursor(new String[] {
BaseColumns._ID,
SearchManager.SUGGEST_COLUMN_TEXT_1,
SearchManager.SUGGEST_COLUMN_TEXT_2,
SearchManager.SUGGEST_COLUMN_ICON_1,
SearchManager.SUGGEST_COLUMN_INTENT_ACTION});
cursor.addRow(new Object[] { 0, "Plants", "Search Plants", android.R.drawable.ic_menu_search, Search.SEARCH_PLANTS_ACTION});
cursor.addRow(new Object[] { 1, "Birds", "Search Birds", android.R.drawable.ic_menu_search, Search.SEARCH_BIRDS_ACTION });
return new MergeCursor(new Cursor[] { cursor });
}
}
我想从我的字符串资源文件中获取“植物”和“鸟类”等术语的本地化字符串。
我该怎么做?
感谢。
答案 0 :(得分:1)
尝试类似:
String value = this.getContext()。getResources()。getString(R.string.Plants)