Android的:如何获得父视图的ID? [英] Android: How to get the ID of a parent View?

查看:722
本文介绍了Android的:如何获得父视图的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

View.getRoot()收益查看,所以我们可以很容易地找出哪些是根视图使用 getResourceName(View.getId())

View.getRoot() returns View, so we can easily figure out which is the root view by using getResourceName(View.getId()).

View.getParent() ......,而我希望它也返回查看这是父,实际上只返回 ViewParent 的实例,似乎有非常非常少用的方法/字段。它吮吸。

View.getParent()..., while I expect it also returns View that is the parent, actually only returns an instance of ViewParent that seems to have very very few useful method/fields. It sucks.

那么,有没有什么办法可以知道父母的ID?我相信一个查看的母公司也是查看,因此,它应该具有MID领域。

So, is there any way to know the ID of the parent? I believe a View's parent is also View, thus it should has mID field.

我真的不知道为什么谷歌没有让 View.getParent()只返回查看。这是有道理的,只有当别的其他东西比查看可能是父母,而据我所知,这是仅限于查看和它的子类。

I really wonder why Google didn't let View.getParent() just returns View. It makes sense, only when something else other than View could be the parent, and as far as I know, it's limited to View and its subclasses.

推荐答案

ViewParent 就是这样的观点,即可以有孩子实现一个接口。大部分的时间你回来的类将是的ViewGroup ,如的LinearLayout 或<$ C $的一个实例C>的RelativeLayout 。我不完全相信的名你的意思,但如果你想要得到的类名,你可以这样做总是: view.getParent()的getClass()的getName()

ViewParent is just an interface that any View that can have children implements. Most of the times the class you get back will be an instance of a ViewGroup, like LinearLayout or RelativeLayout. I'm not exactly sure what you mean by "name" but if you want to get the class name you can do so like always: view.getParent().getClass().getName().

这篇关于Android的:如何获得父视图的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆