javaandroidgettype

Android get type of a view


How can i do this?

something:

final View view=FLall.getChildAt(i);

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

Solution

  • 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 ...