当我在Android手机上按下搜索按钮时,我的搜索框没有显示。我想做的是做一个ASyncTask(或后台任务)来获取字符串数组(人名)的JSON响应,搜索结果,并使用IMDB具有的相同搜索功能将其显示给用户。目前,我正在使用字符串数组来测试我的搜索响应/请求。有什么想法吗?
按下搜索按钮时出现以下警告(但我认为这与我的问题无关):
04-21 03:35:23.767: WARN/KeyCharacterMap(12946): Can't open keycharmap file 04-21 03:36:48.978: WARN/KeyCharacterMap(12999): Error loading keycharmap file '/system/usr/keychars/qtouch-touchscreen.kcm.bin'. hw.keyboards.65537.devname='qtouch-touchscreen' 04-21 03:37:21.408: WARN/KeyCharacterMap(2576): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
以下错误由@Heiko Rupp提供:
04-21 03:17:51.994: WARN/SearchableInfo(1293): Invalid searchable metadata for com.redacted/.SearchActivity: Search label must be a resource reference.
SearchActivity.java:
package com.redacted;
import android.app.ListActivity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class SearchActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_results);
handleIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
showResults(query);
}
}
private void showResults(String q) {
String[] listItems = { "test", "my", "search", "list" };
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listItems));
}
}
searchable.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable
xmlns:android="http://schemas.android.com/apk/res/android"
android:searchButtonText="Search"
android:label="Redacted"
android:hint="Redacted"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer">
</searchable>
Manifest Manifest.xml的一部分(元数据在标记内部,因此它是全局的):
<activity android:launchMode="singleTop" android:name="SearchActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<meta-data android:name="android.app.default_searchable"
android:value="SearchActivity" />
</application>
search_results.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ListView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/list"></ListView>
</LinearLayout>
答案 0 :(得分:5)
我遇到了同样的问题.android:label的值必须是字符串资源.Hardcoding字符串不会出错。
答案 1 :(得分:1)
错误消息显示“搜索标签必须是资源引用。”
所以
<searchable
xmlns:android="http://schemas.android.com/apk/res/android"
android:label="Redacted"
错了,应该阅读
<searchable
xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/Redacted"
然后在strings.xml中有一个'Redacted'条目
您的清单显示
android:value="SearchActivity" />
不应该是
android:value=".SearchActivity" />