如何动态注入的LinearLayout多次(Android版)? [英] How to dynamically inject LinearLayout multiple times (Android)?

查看:118
本文介绍了如何动态注入的LinearLayout多次(Android版)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我由含有+和XML版式文件 - 按钮,一个TextView,我能够通过使用到它注入到我的LinearLayout:

Okay, I made a XML Layout file containing a + and - button, and a textView, I was able to inject it into my LinearLayout by using:

    LinearLayout myLayout = (LinearLayout)findViewById(R.id.linearLayout2);
    View injecterLayout = getLayoutInflater().inflate(R.layout.newplayerlayout, myLayout, false);
    myLayout.addView(injecterLayout);

不过,我想能够多次注射,所以我有几个+, - ,并且TextView中的有没有办法做到这一点。

But I would like to be able to inject it multiple times, so I have several +, -, and textView's is there any way to do that?

推荐答案

只要继续使用相同的code创建新objecst?还是我失去了一些东西?

Just keep using the same code to create new objecst? or am I missing something?

View injecterLayout;


    LinearLayout myLayout = (LinearLayout)findViewById(R.id.linearLayout2);
    injecterLayout = getLayoutInflater().inflate(R.layout.newplayerlayout, myLayout, false);
    myLayout.addView(injecterLayout);

    injecterLayout = getLayoutInflater().inflate(R.layout.newplayerlayout, myLayout, false);
    myLayout.addView(injecterLayout);

    injecterLayout = getLayoutInflater().inflate(R.layout.newplayerlayout, myLayout, false);
    myLayout.addView(injecterLayout);

这篇关于如何动态注入的LinearLayout多次(Android版)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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