我想创建一个布局窗体编程。对于这个例子,我想在我的表单中添加一个像textview一样的视图几次。我创建了另一个具有textview的布局,现在我想在当前布局中添加这个textview几次。我怎么能从另一个布局添加一个视图像textview到当前布局android
public class FileForm extends Activity {
LinearLayout LIN_Main;
TextView TV_GroupTitle;
LayoutInflater LYOTInf;
View VIW_AllItems;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_form);
LIN_Main = (LinearLayout) findViewById(R.id.LIN_Main);
LYOTInf = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
VIW_AllItems = LYOTInf.inflate(R.layout.item,null);
TV_GroupTitle = (TextView) VIW_AllItems.findViewById(R.id.TV_GroupTitle);
int INT_GroupNum = 0;
List<Integer> INT_EmNumInGroup = new ArrayList<Integer>();;
EmManager EMM = null;
EMM = EMM.getInstance();
Element EmNode = EMM.getEm();
Element EmG = null;
Element EmE = null;
NodeList Group = null;
NodeList EmList = null;
Group = EmNode.getChildNodes();
INT_GroupNum = Group.getLength();
LIN_Main.removeAllViews();
for (int i=0;i<INT_GroupNum;i++)
{
EmList = Group.item(i).getChildNodes();
INT_EmNumInGroup.add(EmList.getLength());
for (int j=0;j<INT_EmNumInGroup.get(i);j++)
{
EmE = (Element) EmList.item(j);
for(int att=0;att<Integer.parseInt(EmE.getAttribute("Num"));att++)
{
TV_GroupTitle.setText(EmE.getNodeName());
LIN_Main.addView(TV_GroupTitle);
}
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.file_form, menu);
return true;
}
}
但有错误。
感谢我的朋友 –