I am new to java and android development; and I worked on the app in witch. I want an action bar with SearchView . I looked at Google examples, but I can't get it to work. I have to do something wrong, and I'm going to abandon application development: D I searched, but I did not find anything useful. Maybe you guys can help me :)
Problem : I open the search window as it should, but after that nothing happens at all, I noticed that my searchManager.getSearchableInfo (getComponentName ()) returns null. Also, my hint that I gave does not appear in my search box, the witch makes me think that maybe the application cannot find my searchable.xml? Just talk :)
MainActivity.java
public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu);
searchable.xml
<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:hint="@string/search_hint" android:label="@string/app_label"> </searchable>
Androidmanifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.searchapp" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".SearchableActivity" > <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> </activity> <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/> </application> </manifest>
SearchableActivity.java
package com.example.searchapp; import android.app.ListActivity; import android.app.SearchManager; import android.content.Intent; import android.os.Bundle; import android.util.Log; public class SearchableActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search);
And here is the link to the mentioned project, I would be eternally grateful if someone would help me with this!
Source
android android-actionbar searchview
Jonathan Andersson Jul 28 '12 at 7:35 2012-07-28 07:35
source share