2013-07-16 44 views
0

使用R.layout一個觀點,我有兩個個XML:我能否在Java

  • main_layout.xml
  • item_layout.xml

有在main_layout一個LinearLayout具有ID R.id.customContainer 。 如何編程式<include>秒佈局(使用某種方式R.layout.item_layout?)到我的customContainer

我已經參考ViewGroup customContainer,但addView方法接受View - 我不知道如何創建只有xml佈局文件。

回答

4
View view = LayoutInflater.from(context).inflate(R.layout.item_layout, customContainer, false); 
customContainer.addView(view); 
+0

它代替了'customContainer'中的所有內容,我可以追加而不是替換嗎? –

+0

請參閱編輯。 – alex

+0

謝謝,完美的作品:) –