gpt4 book ai didi

java - 安卓 : How to get view class from a view to use with instanceOf

转载 作者:行者123 更新时间:2023-11-29 04:28:42 25 4
gpt4 key购买 nike

我试图通过返回第一个 View 找到的 View 来在 View 组内按类型获取 View 。

private View findViewByType(ViewGroup p, View v) {
for (int i = 0; i < p.getChildCount(); i++)
if (p.getChildAt(i) instanceof v.getClass())
return p.getChildAt(i);
}

我似乎无法让 view.getClass() 工作。如何从 View 中获取类?

最佳答案

一种方法是

p.getChildAt(i).getClass().isInstance(v)

isIsntance(Object) 确定指定的 Object 是否与此 Class 表示的对象赋值兼容。您可以阅读文档 here

关于java - 安卓 : How to get view class from a view to use with instanceOf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44841550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com