Mono Android Search Dialog

I am trying to implement a search dialog in a Mono Android application for documentation here: http://developer.android.com/guide/topics/search/search-dialog.html

I have an activity that the user should be able to search at:

[Activity (Label = "MyActivity", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/MyStyle")] [MetaData ("android.app.default_searchable", Value = ".SearchActivity")] public class MainActivity : BaseActivity {... 

I have a search operation (where there will be a heavy climb):

 [Activity(Theme = "@style/MyStyle", Label = "Searchable", LaunchMode = Android.Content.PM.LaunchMode.SingleTop)] [IntentFilter(new[] { Intent.ActionMain }, Categories = new[] { Intent.CategoryLauncher, Intent.ActionSearch })] [MetaData("searchable", Resource = "@xml/searchable")] public class SearchActivity : BaseActivity { ... 

And I have my searchable.xml:

 <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="MyLabel" android:hint="Search Products"> </searchable> 

When I press the search key on the phone in MainActivity, nothing happens - there is no dialogue. I think my problem is how attributes translate to AndroidManifest.xml at runtime, but I'm not sure.

UPDATE 1/3/2012: I published a project deferred to the most basic elements. Press the search button on your Android and you will see SearchDialog, but it will not appear: Demo project here

+7
source share
3 answers

The problem is the [MetaData] attribute on MainActivity . If you provided the correct version of the class class with names, the search dialog will appear correctly:

 [MetaData ("android.app.default_searchable", Value = "searchdialogtest.SearchActivity")] public class MainActivity : BaseActivity { 
+4
source

in your serachable.xml file you cannot have a constant string as a name and a hint ... they must be linked dynamically @string/my_app_name @string/my_hint

and everything works great!

+1
source

I feel. In the manifest file, the streamlined metadata tag is not correct (android: name = "android.app.searchable")

Manifest Example - MainActivity Tag -

<activity android:name=".MainActivity"> <meta-data android:name="android.app.default_searchable" android:value="pckname.SearchClass"/> </activity>

SearchActivity Tag -

 <activity android:name=".SearchActivity" > <intent-filter> <action android:name="android.intent.action.SEARCH" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /></activity> 
0
source

All Articles