私は完全に立ち往生しており、これに対する可能な解決策を読むのに何時間も費やしてきました。検索アクティビティを開始できません。
メインアクティビティがあり、そこから検索ボタンで検索アクティビティを開始します。
ファイルMainApp.java
public class MainApp extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainapplayout);
}
public boolean onCreateOptionsMenu(Menu m){
getMenuInflater().inflate(R.menu.mainappmenu,m);
return true;
}
public boolean onOptionsItemSelected(MenuItem m) {
if(m.getItemId()==R.id.menu_search){
return onSearchRequested(); // THIS IS CALLED, AND RETURNS TRUE
}else return false;
}
}
UIボタンを押しても、ハードウェア検索キーを押しても、検索は呼び出されません。
onSearchRequested()
間違いなく呼び出され、を返しますtrue
。
ファイルAndroidManifest.xml
:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.homphysiology.lists"
android:versionCode="1" android:versionName="1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="8" />
<application
android:name="org.homphysiology.lists.MainApp"
****REMOVED THIS LINE NOW, thanks arju, still not working tho
android:icon="@drawable/ic_launcher">
<activity android:name="org.homphysiology.lists.MainApp">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value="org.homphysiology.lists.SearchActivity"
/>
</activity>
<activity android:name="org.homphysiology.lists.SearchActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
****REMOVED THIS LINE NOW, thanks tushar, still not working tho
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable"
/>
</activity>
</application>
</manifest>
そして私は以下を持っています:
ファイルres/xml/searchable.xml
:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schamas.android.com/apk/res/android"
android:label="@string/search_label"
android:hint="@string/search_hint"
/>
これらの文字列はにあり/res/values/strings.xml
ます。
検索アクティビティ自体は単純ですが、作成されることはありません。コンストラクターにブレークポイントがあります。
ファイルSearchActivity.java
:
public class SearchActivity extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setListAdapter(...)
}
}
誰かがここで問題を見つけることができますか?[Eclipse Juno 4.2.1、SDK 21.0.1でコンパイル、HTCDesireZでテスト]ありがとう...
補遺
((SearchManager)getSystemService(Context.SEARCH_SERVICE))
.getSearchableInfo(getComponentName())
を返しますnull
。たぶん、これは私のSearchActivity
登録が適切に行われていないという事実を打ち負かしているだけなのかもしれません...
@arjuの提案を変更する:次を使用して「手動で」検索アクティビティを開始できます
boolean onOptionsItemSelected(MenuItem m){
startActivity(new Intent(this,SearchActivity.class));
return true;
}
ただし、もちろん、これはハードウェアボタンでは機能しません。さらに、システム検索ダイアログは表示されません。
また、メインアクティビティではなく、アプリケーション全体の検索メタデータを設定してみました。
<manifest>
<application>
<activity ...MainApp... > ... </activity>
<activity ...SearchActivity... > ... </activity>
<meta-data
android:name="android.app.default_searchable"
android:value="org.homphysiology.lists.SearchActivity"
/>
</application>
</manifest>
同じ問題!検索アクティビティがインスタンス化されることはありません。