Skip to content

Instantly share code, notes, and snippets.

@jamesmontemagno
Created February 1, 2014 19:29
Show Gist options
  • Save jamesmontemagno/8757341 to your computer and use it in GitHub Desktop.
Save jamesmontemagno/8757341 to your computer and use it in GitHub Desktop.
Search-Android
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Support.V4.View;
namespace XamarinCast
{
[Activity (Label = "Optimized Adapter", MainLauncher = true, Theme = "@android:style/Theme.Holo.Light")]
public class MainActivity : Activity, MenuItemCompat.IOnActionExpandListener
{
public bool OnMenuItemActionCollapse (IMenuItem item)
{
return true;
}
public bool OnMenuItemActionExpand (IMenuItem item)
{
return true;
}
int count = 1;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate {
button.Text = string.Format ("{0} clicks!", count++);
};
}
public override bool OnCreateOptionsMenu (IMenu menu)
{
MenuInflater.Inflate (Resource.Menu.home, menu);
var item = menu.GetItem (0);
var searchView = (SearchView)MenuItemCompat.GetActionView (item);
MenuItemCompat.SetOnActionExpandListener (item, this);
return base.OnCreateOptionsMenu (menu);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/search_menu"
android:title="search"
android:showAsAction="ifRoom|withText"
android:actionViewClass="android.widget.SearchView">
</item>
</menu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment