How can I set an ActionBar button enabled=true, from a ListView_ItemClick?

I have this code:

public override bool OnCreateOptionsMenu(IMenu menu)
        {
            MenuInflater.Inflate(Resource.Drawable.actionbar_produtos, menu);
            menu.FindItem (Resource.Id.edita).SetEnabled (false);
            menu.FindItem (Resource.Id.apaga).SetEnabled (false);
            return base.OnCreateOptionsMenu(menu);
        }

        public override bool OnOptionsItemSelected(IMenuItem item)
        {

            switch (item.ItemId)
            {

            case Resource.Id.search:
                //Search icon has been clicked

                mSearch.Focusable=false;
                mSearch.Visibility = ViewStates.Visible;
                if (mIsAnimating)
                {
                    return true;
                }

                if (!mAnimatedDown)
                {
                    //Listview is up
                    MyAnimation anim = new MyAnimation(ListViewProdutos, ListViewProdutos.Height - mSearch.Height);
                    anim.Duration = 500;
                    ListViewProdutos.StartAnimation(anim);
                    anim.AnimationStart += anim_AnimationStartDown;
                    anim.AnimationEnd += anim_AnimationEndDown;
                    mContainer.Animate().TranslationYBy(mSearch.Height).SetDuration(500).Start();


                }

                else
                {
                    //Listview is down
                    MyAnimation anim = new MyAnimation(ListViewProdutos, ListViewProdutos.Height + mSearch.Height);
                    anim.Duration = 500;
                    ListViewProdutos.StartAnimation(anim);
                    anim.AnimationStart += anim_AnimationStartUp;
                    anim.AnimationEnd += anim_AnimationEndUp;
                    mContainer.Animate().TranslationYBy(-mSearch.Height).SetDuration(500).Start();


                }

                mAnimatedDown = !mAnimatedDown;
                return true;

            case Resource.Id.adiciona:

                FragmentTransaction transaction = FragmentManager.BeginTransaction();

                dialog_Adicionar_produto dialog_adicionar = new dialog_Adicionar_produto ();
                dialog_adicionar.Show (transaction, "dialog fragment");

                dialog_adicionar.mOnAdicionarComplete += dialog_adicionar_mOnAdicionarComplete;



                return true;

            case Resource.Id.edita:

                FragmentTransaction transaction2 = FragmentManager.BeginTransaction ();




                dialog_Editar_produto dialog_editar = new dialog_Editar_produto (array);
                dialog_editar.Show (transaction2, "dialog fragment");

                dialog_editar.mOnEditarComplete += dialog_editar_mOnAdicionarComplete;



                return true;

            case Resource.Id.apaga:


                mItems.RemoveAt (index );
                adapter = new MyListViewAdapter_produtos (this,Resource.Layout.listview_row_produtos, mItems);
                ListViewProdutos.Adapter = adapter;


                return true;

            default:
                return base.OnOptionsItemSelected(item);
            }
        }

And I would like that when the user clicks on an item (of an listview) those "apaga" and "edita" to turn enabled=true.

here it is the listview_ItemCLick:

protected void ListViewProdutos_ItemClick (object sender, AdapterView.ItemClickEventArgs e)
        {
            index = e.Position;
            adapter.setSelectedIndex(e.Position);

            array [0] = mItems [e.Position].Nome;
            array [1] = Convert.ToString(mItems [e.Position].Preco);
            array [2] = mItems [e.Position].Unidade;
            array [3] = mItems [e.Position].Categoria;

            ListViewProdutos.Adapter = adapter;


        }

How can I access the menu items from here?

Best Answer

Answers

  • MihaMarkicMihaMarkic SI ✭✭✭✭

    Try calling invalidateOptionsMenu() and when menu gets recreated set its properties.

  • could you exemplify with code?

Sign In or Register to comment.