获取父布局中所有按钮的ID

编程入门 行业动态 更新时间:2024-10-27 06:19:41
本文介绍了获取父布局中所有按钮的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Eclipse在Java中开发Android应用.

I'm developing an Android app in java with eclipse.

我的XML中有2种相对布局.一种布局中有2个按钮,另一种布局中有3个按钮.我正在尝试一些如何在其中包含两个按钮的相对布局中检索按钮的所有ID的方法.

I have 2 Relative layouts within my XML. One layout has 2 buttons within it and the other has 3 buttons. I'm trying to some how retrieve all the id's of the buttons in the relative layout that has the two buttons inside of it.

推荐答案

在父视图中循环以获取所有子视图

Loop through parent view to get all child views

ViewGroup parentView = (ViewGroup) findViewById(R.id.linearLayout1); for(int i=0; i < parentView.getChildCount(); i++) { View childView = parentView.getChildAt(i); int resID = childView.getId(); }

更多推荐

获取父布局中所有按钮的ID

本文发布于:2023-10-26 10:08:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   按钮   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!