1

你好,我正在开发一个应用程序,我想在现有布局的卡片视图中充气布局。而且我想根据我的字符串数组动态显示文本视图列表。如何在使用动态线性布局的现有布局中使用自定义布局

这里是我的现有布局

,我想夸大按照上述布局的最后cardview布局

所以试图用编码来做到这一点,但它仅显示一个TextView的

我的编码是如下 但它不工作它只显示一个文本视图 我想根据我的字符串大小动态地添加textview

我想inflaate布局就像列表视图,但我不希望使用listview.i要实现这一点没有列表视图动态

回答

0

它只能显示一个TextView的我想补充的TextView动态 根据我的字符串大小

可能是由于每次为每个TextView充气inflate_specification并在for循环中初始化container

做得一样:在我的答案在做的时候看到我的编辑答案,什么事情发生:

LinearLayout container = (LinearLayout)findViewById(R.id.temp); 
LayoutInflater inflater = (LayoutInflater) getApplicationContext(). 
         getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

for(int i=0;i<5;i++) 
    { 
    View view = inflater.inflate(R.layout.inflate_specification, container,false); 
    // Create TextView 
     TextView product = (TextView)view.findViewById(R.id.speci); 
     product.setText("i= " + i); 

     container.addView(view); 
    } 
+0

@unknownapk? –

+0

它不工作 –

0

试试这个代码:

LinearLayout container = (LinearLayout)findViewById(R.id.temp); 
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
container.removeAllViews(); 
for(int i=0;i<5;i++) { 
    View view = inflater.inflate(R.layout.inflate_specification, container,false); 
    // Create TextView 
    TextView product = (TextView)findViewById(R.id.speci); 

    product.setText("i= " + i); 

    container.addView(view); 

} 
+0

ü使用相同的代码,代码 –

+0

R,看在我的代码,否则它会覆盖 – Lokesh

+0

因为u必须申报容器退出循环不工作先生 – Lokesh