Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search Dialog in Mono Android

I'm trying to implement a search dialog in a Mono Android app per the documentation here: http://developer.android.com/guide/topics/search/search-dialog.html

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

[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 searchable activity (where the heavy-lifting will happen):

[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 the MainActivity, nothing happens - no dialog. I think my problem lies with how the attributes are being translated into the AndroidManifest.xml at runtime but I'm not sure.

UPDATE 1/3/2012: I have posted a project distilled down to the most basic elements here. Press the search button on your Android and you should see the SearchDialog but it doesn't appear: Demo Project Here

like image 335
profexorgeek Avatar asked Dec 15 '11 19:12

profexorgeek


1 Answers

The problem is in the [MetaData] attribute on MainActivity. If you provide the properly namespaced version of the class the search dialog appears correctly:

[MetaData ("android.app.default_searchable", Value = "searchdialogtest.SearchActivity")]
public class MainActivity : BaseActivity {
like image 157
Greg Shackles Avatar answered Sep 25 '22 01:09

Greg Shackles