検索機能を追加したいアプリがあります。説明どおりに実装しようとしてdeveloper.android
いますが、エミュレータで検索をクリックしてもアクティビティが開始されません。問題は何ですか?
SearchActivity.java
public class SearchActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); handleIntent(getIntent()); } @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); handleIntent(intent); } public void onListItemClick(ListView l, View v, int position, long id) { // call detail activity for clicked entry } private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query =intent.getStringExtra(SearchManager.QUERY); doSearch(query); } } private void doSearch(String queryStr) { // get a Cursor, prepare the ListAdapter // and set it } }
xml/searchable.xml
<?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/srchHint" android:inputType="textCapCharacters"> </searchable>
AndroidManifest.xml
(以下のコードは他のアクティビティを示していません)<application> <!-- other actvities --> <activity android:label="@string/app_name" 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> </application>
すでに試したこと:
1.StackOverflowで同様の質問とその解決策を確認します
2. grokkingandroidとedumobileのチュートリアルを見てください、それらは私の問題を助けませんでした。
3.chat.stackoverflowで人々に尋ねる時間を費やします
問題/質問
1.わかりました。doSearch()
メソッドはありますが、クエリを正確に実行する方法と、dbからの結果を表示する方法(可能であれば、例を示すために小さなdbを取得します)、結果を入力する方法。
2.エミュレータで検索をクリックしても、検索アクティビティが開始されません。
3.何を正確に覚えておくべきか、ものとは別に検索を設計するときdeveloper.android
、サイトが何度も教えていない他の詳細。
4.全文検索を実行する方法、私はそれについて読んだ、developer.android
私のデータベースがFTSを持つのに良い方法
PS:私はAndroidを学ぶのは初めてなので、新人の間違いがある場合は、それを我慢してください。手順をスキップしないでください。