Android Example [B4X] SELECT - don't waste tags

Discussion in 'Tutorials & Examples' started by LucaMs, Oct 28, 2019.

  1. LucaMs

    LucaMs Expert Licensed User

    [A simple suggestion, not addressed to "experts"]

    I am almost certain that some members, having to identify which view triggered an event, use the tags.

    For example:

    You have a kind of menu, which is composed of 3 ImageViews:

    Dim ivPictures As ImageView
    Dim ivTexts As ImageView
    Dim ivOther As ImageView

    which event name is unique, "MenuItem".

    One way (quite common, I've read) is to use the tags of those Imageviews.
    You set their tags by Designer:

    ivPictures.Tag set to "Pictures"
    ivTexts.Tag set to "Texts"
    ivOther.Tag set to "Other"

    Then, in your code you have:
    Sub MenuItem_Click
    Dim IV As ImageView = Sender
    Select IV.Tag
    Case "Pictures"
          Case "Texts"
          Case "Other"
        End Select
    This way you "waste" the tag property and also, if you will change something, you have to change the source code AND the tags by Designer.

    You can much more simply compare the objects, the views:
    Sub MenuItem_Click
    Select Sender
    Case ivPictures
          Case ivTexts
          Case ivOther
       End Select

    The same can be applied to groups of views of any kind, obviously, like buttons, for example.
    Last edited: Oct 28, 2019
  2. AnandGupta

    AnandGupta Active Member Licensed User

    Wow ! Thanks for the idea/head up.
    This is much simpler, from my point of view (a beginner) and matches with my logic in HMG/Xbase++.


    LucaMs likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice