Android get type of a view

前端 未结 5 1467
别那么骄傲
别那么骄傲 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:22

    For Others who check this Question,in some cases instanceof does not work(I do not know why!),for example if your want to check if view type is ImageView or ImageButton(i tested this situation) , it get them the same, so you scan use this way :

    //v is your View
        if (v.getClass().getName().equalsIgnoreCase("android.widget.ImageView")) {
            Log.e("imgview", v.toString());
            imgview = (ImageView) v;
        } else if (v.getClass().getName().equalsIgnoreCase("android.widget.ImageButton")) {
            Log.e("imgbtn", v.toString());
            imgbtn = (ImageButton) v; 
        }
    

提交回复
热议问题