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
?
Asked
Active
Viewed 370 times
3

hasanghaforian
- 13,858
- 11
- 76
- 167
-
Are you talking about this: http://stackoverflow.com/questions/2695646/declaring-a-custom-android-ui-element-using-xml or something else? – Morrison Chang Apr 08 '13 at 05:29
-
@MorrisonChang Oh,no... .It is in about creating and using customview from xml.But my question is in about how I can detect my customview is inflated from which layout? – hasanghaforian Apr 08 '13 at 05:34
-
@hasanghaforian you mean you want to get the file name of the inflated xml file? – Pragnani Apr 08 '13 at 05:42
-
@Pragnani Yes,if it is possible. – hasanghaforian Apr 08 '13 at 05:43
-
1@hasanghaforian Nothing is impossible...just set contentDescription for your view, and identify your view based on the contentDescription – Pragnani Apr 08 '13 at 05:48
1 Answers
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
- 9,035
- 2
- 28
- 42