首页 > 移动平台 > 详细

Android 通过根视图取得所有子视图

时间:2015-05-23 01:14:00      阅读:2280      评论:0      收藏:0      [点我收藏+]

LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main_container);
OnClickListener listener = new NewClickListener();
Logger.Logger_d("linearLayout.getChildCount:"+linearLayout.getChildCount());

打印出所有子视图数量

for (int i = 0; i < linearLayout.getChildCount(); i++) {
  View view = linearLayout.getChildAt(i);
  if (view instanceof Button) {
    view.setOnClickListener(listener);
  }
}

得到子视图,查看视图继承关系进行下一步操作

Android 通过根视图取得所有子视图

原文:http://www.cnblogs.com/whhqhy/p/Android.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!