Issue
I am struggling finding how to implement this Java code in Xamarin.
I have tried searchView.Close += delegate { };
but it doesn't work.
searchMI.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
Toast.makeText(getApplicationContext(), "MenuItem#onMenuItemActionExpand", Toast.LENGTH_SHORT).show();
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
Toast.makeText(getApplicationContext(), "MenuItem#onMenuItemActionExpand", Toast.LENGTH_SHORT).show();
return true;
}
});
Solution
Thanks for your answer, it didn't work at first, I had an exception
This is not supported use menuitemcompat.setonactionexpandlistener()
I had to do this instead
At the top of my file :
using MenuItemCompat = Android.Support.V4.View.MenuItemCompat;
In OnCreateOptionsMenu() when I create the search view.
IMenuItem searchItem = menu.FindItem(Resource.Id.searchItem);
MenuItemCompat.SetOnActionExpandListener(searchItem, new ExpandListener(this));
And finally the listener class
class ExpandListener : Java.Lang.Object, MenuItemCompat.IOnActionExpandListener
{
Context context;
public ExpandListener(Context pContext)
{
context = pContext;
}
public bool OnMenuItemActionCollapse(IMenuItem item)
{
//MyStuff with context
return true;
}
public bool OnMenuItemActionExpand(IMenuItem item)
{
//Stuff
return true;
}
}
Answered By - Yohan Dahmani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.