简体   繁体   English

如何多次动态注入LinearLayout(Android)?

[英]How to dynamically inject LinearLayout multiple times (Android)?

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: 好的,我制作了一个包含+和-按钮以及textView的XML Layout文件,可以使用以下命令将其注入到LinearLayout中:

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

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? 但是我希望能够多次注入它,所以我有几个+,-和textView,有什么方法可以做到这一点?

Just keep using the same code to create new objecst? 只是继续使用相同的代码来创建新的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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM