Android get type of a view

lacas picture lacas · Nov 7, 2010 · Viewed 58.1k times · Source

How can i do this?

something:

final View view=FLall.getChildAt(i);

if (view.getType()==ImageView) {
...
}

Answer

Felix picture Felix · Nov 7, 2010

If, for some strange reason, you can't use Asahi's suggestion (using tags), my proposition would be the following:

if (view instanceof ImageView) {
    ImageView imageView = (ImageView) view;
    // do what you want with imageView
}
else if (view instanceof TextView) {
    TextView textView = (TextView) view;
    // do what you want with textView
}
else if ...