Android, switch/case on View with programmatically generated views

15,667

Solution 1

EDIT: You should create ids.xml file and refer it in your code while creating view programmatically.

Solution 2

You could do View.setId() when you create your views.

Share:
15,667
Hamid
Author by

Hamid

Updated on June 04, 2022

Comments

  • Hamid
    Hamid almost 2 years

    Normally, when I switch/case my views onClick, I have no problems because they were defined in the XML and have ID's so I use:

    switch(v.getID())
    {
    case(R.id.someButton):
    {
      // do something
    }
    default: // bla
    }
    

    However, I am now defining my views programatically and so they don't have a static ID.

    How should I now switch on these views? if I tried getID() on the views it's not allowed because it isn't static.

    Ideas? Thanks.