Android get type of a view

前端 未结 5 1468
别那么骄傲
别那么骄傲 2020-12-08 12:44

How can i do this?

something:

final View view=FLall.getChildAt(i);

if (view.getType()==ImageView) {
...
}
5条回答
  •  暖寄归人
    2020-12-08 13:45

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

提交回复
热议问题