3

I inflate some layouts during running of App and store them in a variable of type View.I know that I can set a Tag for view after inflating it and check it to detect it's type,but is there another way to detect it?For example a method like instanceof?

hasanghaforian
  • 13,142
  • 8
  • 71
  • 144

1 Answers1

0

Try something like this

 View yourView1=(View)findViewById(R.id.yourView1);

     boolean isMyView=false; 
        try{
           YourView yv=(YourView)yourView1;
     isMyView=true;
        }
        catch (ClassCastException e)
        {
     isMyView=false; 
            e.printStackTrace();
        }

    if(isMyView)
       {
         //OK it is yourView
        }
Arun C
  • 8,907
  • 1
  • 25
  • 42