动态克隆在Android的一个LinearLayout中? [英] dynamically cloning a LinearLayout in android?

查看:182
本文介绍了动态克隆在Android的一个LinearLayout中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有与它为.xml文件中的一些元素的LinearLayout。 在Java中,我需要以某种方式克隆了几次,到一个数组,编辑一些它的孩子,然后遍历数组,将每个的LinearLayout我的主要观点。

你认为什么是正确的方式来克隆从XML文件这样的布局到Java中的数组元素?

谢谢!

解决方案

  LayoutInflater VI =(LayoutInflater)myContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
V = vi.inflate(R.layout.yourLayoutId,NULL);
 

您可以做一些事情是这样膨胀的观点,然后修改iside使用findViewById方法视图中的元素。希望这将有助于

Say I have a LinearLayout with some elements in it as an .xml file. In Java, I need to somehow "clone" it a few times into an array, edit some of its children, and then loop through the array, adding each LinearLayout to my main view.

What do you think would be the correct way to "clone" this layout from an xml file into an array element in java?

Thanks!

解决方案

LayoutInflater vi = (LayoutInflater) myContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.yourLayoutId, null);

you can do some thing like this to inflate the view, and then modify the element iside the view using the findViewById method. Hope this will help

这篇关于动态克隆在Android的一个LinearLayout中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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