Forum Xamarin.Android

how to get the TAG from the button

Im trying to do a switch case using the tag from the button but i cant any suggestions?


  • KeyzerSKeyzerS NOMember ✭✭


    I had a similar issue in a custom list adapter, where I have a button to reset the item without opening it. Since the eventhandler is in the viewholder, I needed to catch the tag to determine which item to reset. This is how I ended up doing it there:

    I set the tag like this:

       holder.buttonReset.SetTag (Resource.Id.buttonReset, position);

    And then I get it in the eventhandler like this:

      holder.buttonReset.Click += (object sender, EventArgs e) => {
                    int pos = (int) (((Button) sender).GetTag(Resource.Id.buttonReset));
                    var currentItem2 = this[pos];

    You can use pos in a switch too. But im not sure I get your issue. So please elaborate on it, if this doesnt help.

  • Monica.0316Monica.0316 USMember

    thank you keyzerS it worked

Sign In or Register to comment.