Android的搜索活动无法启动 [英] Android search activity not starting
问题描述
我的搜索框没有显示时,我在$我的Android手机p $ PSS搜索按钮。我想要做的就是做一个AsyncTask的(或后台任务)来获得字符串(人名)的数组的JSON响应,通过搜索的结果,并使用IMDB具有相同的搜索功能,它显示给用户。目前,我用一个字符串数组来测试我的搜索响应/请求。任何想法?
我得到以下警告,当pressing搜索按钮(但我认为这是不相关的,以我的问题):
三月四日至21日:35:23.767:WARN / KeyCharacterMap(12946):无法打开keycharmap文件 3月4号至21号:36:48.978:WARN / KeyCharacterMap(12999):错误加载keycharmap文件/system/usr/keychars/qtouch-touchscreen.kcm.bin。 hw.keyboards.65537.devname ='QTouch软件,触摸屏 3月4号至21号:37:21.408:WARN / KeyCharacterMap(2576):使用默认的键盘对应:/system/usr/keychars/qwerty.kcm.bin
下面的错误已得到修复礼貌@Heiko鲁普的:
三月四日至21日:17:51.994:WARN / SearchableInfo(1293):无效的搜索元数据com.redacted / .SearchActivity:搜索标签必须是一个资源引用
SearchActivity.java:
包com.redacted;
进口android.app.ListActivity;
进口android.app.SearchManager;
进口android.content.Intent;
进口android.os.Bundle;
进口android.widget.ArrayAdapter;
公共类SearchActivity扩展ListActivity {
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.search_results);
handleIntent(getIntent());
}
@覆盖
保护无效onNewIntent(意向意图){
setIntent(意向);
handleIntent(意向);
}
私人无效handleIntent(意向意图){
如果(Intent.ACTION_SEARCH.equals(intent.getAction())){
查询字符串= intent.getStringExtra(SearchManager.QUERY);
showResults(查询);
}
}
私人无效showResults(串Q){
的String []时listItems = {测试,我的,搜索,清单};
setListAdapter(新ArrayAdapter<字符串>(这一点,
android.R.layout.simple_list_item_1,listItems中));
}
}
searchable.xml:
< XML版本=1.0编码=UTF-8&GT?;
<搜索
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:searchButtonText =搜索
机器人:标签=绝密
机器人:提示=绝密
机器人:voiceSearchMode =showVoiceSearchButton | launchRecognizer>
< /搜索>
清单的Manifest.xml的部分(元数据是内部标记,以便它是全球):
<活动机器人:launchMode =singleTop机器人:NAME =SearchActivity>
<意向滤光器>
<作用机器人:名称=android.intent.action.SEARCH/>
&所述; /意图滤光器>
<元数据的android:NAME =android.app.searchable
机器人:资源=@ XML /搜索/>
< /活性GT;
<元数据的android:NAME =android.app.default_searchable
机器人:值=SearchActivity/>
< /用途>
search_results.xml:
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent机器人:layout_height =match_parent>
< ListView的机器人:layout_height =WRAP_CONTENT机器人:layout_width =match_parent机器人:ID =@ + ID /列表>< / ListView控件>
< / LinearLayout中>
我在为Android的相同problem.The值:标签必须是一个字符串resource.Hardcoding字符串将不会铁锅
My search box is not displaying when I press the search button on my Android phone. What I want to do is do an ASyncTask (or background task) to get a JSON response of an array of strings (names of people), search through the result, and display it to the user using the same search functionality that IMDB has. Currently, I'm using a string array to test my search response/request. Any ideas?
I get the following warnings when pressing the search button (but I think this is unrelated to my issue):
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
The error below has been fixed courtesy of @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>
Part of Manifest Manifest.xml (meta-data is inside tag so it's global):
<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>
I got in to the same problem.The value for android:label must be a string resource.Hardcoding strings won't wok.
这篇关于Android的搜索活动无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!