我希望能够在一个LinearLayout中填充多个另一个LinearLayout的实例。我该怎么做? 我的问题是,似乎我总是使用相同的实例,因此一遍又一遍地添加该实例。
简而言之: 我需要一种方法将LinearLayout子项的新实例添加到另一个LinearLayout父项中。
到目前为止,我已经做了以下工作:
简而言之: 我需要一种方法将LinearLayout子项的新实例添加到另一个LinearLayout父项中。
到目前为止,我已经做了以下工作:
private void setupContainers() {
LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(MainActivity.LAYOUT_INFLATER_SERVICE);
LinearLayout parentContainer = (LinearLayout)this.findViewById(R.id.parent_container);
for (int i = 0; i < someNumber; i++) {
LinearLayout childContainer = (LinearLayout) layoutInflater.inflate(R.layout.child_container, null);
parentContainer.addView(childContainer);
}
}