Actionbar submenu open programmatically

UgurKurkcuUgurKurkcu TRMember
edited May 2014 in Xamarin.Android

hi
i am using Android Support Library v7: Hello ActionBarCompat

I have optionsmenu on actionbar and i add submenus on it.
When i click bluetooth submenu it start activity and reCreate optionsmenu after result.
i wanna Open newCreated submenu programmatically.

how can do this.

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        if (requestCode == RequestCode.BlueTooth.ActionRequestEnable)
        {
            SupportInvalidateOptionsMenu();
        }

    }

    public override bool OnCreateOptionsMenu(IMenu menu)
    {
        var xBlueToothSubMenu = menu.AddSubMenu("BlueTooth")
            .SetHeaderIcon(Resource.Drawable.BlueTooth_Actionbar)
            .SetHeaderTitle("BlueTooth devices");

        if (BlueToothControl.BlueToothAdapter.IsEnabled)
        {
            foreach (string xAdapter in BlueToothControl.PairedDevices)
            {
                var xIMenuItem = xBlueToothSubMenu.Add(xAdapter)
                    .SetIcon(Resource.Drawable.BlueTooth_Actionbar);
            }

            xBlueToothSubMenu.SetIcon(Resource.Drawable.BlueTooth_Active);

            // here I wanna Open this submenu (xBlueToothSubMenu) again
        }
        else
        {
            xBlueToothSubMenu.SetIcon(Resource.Drawable.BlueTooth_Passive);

        }


        Android.Support.V4.View.MenuItemCompat.SetShowAsAction(xBlueToothSubMenu.Item, Android.Support.V4.View.MenuItemCompat.ShowAsActionIfRoom);

        //return true;
        return base.OnCreateOptionsMenu(menu);
    }

    public override bool OnOptionsItemSelected(IMenuItem item)
    {
        if (item.TitleFormatted.ToString() == "BlueTooth")
            StartActivityForResult(typeof(BlueToothControl), RequestCode.BlueTooth.ActionRequestEnable );

        return base.OnOptionsItemSelected(item);
    }
Sign In or Register to comment.