Android的:在Android反复创造这样的XML布局? [英] Android: Repeatedly create such xml Layout in android?

查看:119
本文介绍了Android的:在Android反复创造这样的XML布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建的布局(XML或Java中),像下面图片:

I have to create the Layout (in xml or in java) as like Below image :

但是,应该重复每条件。
假设,如果Arraylist.size()更多的则是2,那么整个布局应该重复这样的时间。
这可能吗?

But it should be repeated as per the Condition. Suppose, if the Arraylist.size() is more then 2 then the whole layout should be repeated as such time. is it possible?

如果是的话让我知道它是如何可能的。

if yes then let me know how it is possible.

我要创建线性布局verticle方向上的这种布局。

I want to create such layout in verticle direction of the linear layout.

感谢。

编辑:
与jin35答案我已经做过这样的:

Edited: with jin35 answer i have done like this:

private void doCalculationForMultipleEmployee() {
    singleEmployee.setVisibility(View.GONE);
    for (int i = 0; i<=tempEmployerList.size()-1; i++) {     
        View repeatedLayout = LayoutInflater.from(getApplicationContext()).inflate(R.layout.test);     
        ((TextView)repeatedLayout.findViewById(R.id.list_title)).setText("Employee"+i);     
        // customize repeatedLayout with other data     
        myLinearLayout.addChild(repeatedLayout); 
    }
}

但我在.inflate,并在得到了Syntex错误.addChild
请帮我了点。
什么问题呢?

But i got syntex error at .inflate and at .addChild Please help me for that. Whats wrong with that ?

推荐答案

您应该创建的LinearLayout XML文件,并与您另一个XML重复的布局。然后在code数据的每一部分只使用这样的:

You should create xml file with LinearLayout and another xml with you "repeating" layout. Then in code for every part of data just use this:

for (Employee e : employeeList) {
    View repeatedLayout = LayoutInflater.from(context).inflate(R.your_repeated_layout);
    ((TextView)repeatedLayout.findViewById(R.id.employee_salary)).setText(e.getSalary())
    // customize repeatedLayout with other data
    yourLinearLayout.addChild(repeatedLayout);
}

这篇关于Android的:在Android反复创造这样的XML布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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