0
当我单击按钮时,应该如何将相同的片段重复显示为相同的布局?当我尝试在线性布局下重复使用相同的片段时,它只会添加第一个片段而不是其他片段。单击按钮时,将相同的片段重复为相同的布局
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_4);
problemsLayout = (LinearLayout)findViewById(R.id.problemsLayout);
FragmentManager fragmentManager =getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
for(int i =0 ; i<OperationProblemSelectTask.operationProblemList.size();i++){
addProblemView(fragmentTransaction,OperationProblemSelectTask.operationProblemList.get(i).getMahine_problem(),OperationProblemSelectTask.operationProblemList.get(i).getMachine());
Log.i("OperationProblemSelectTaskObjects",""+OperationProblemSelectTask.operationProblemList.get(i).getMahine_problem());
}
fragmentTransaction.commit();
(MachineProblemFragment)getSupportFragmentManager().findFragmentById(R.id.fragment3);
}
public void addProblemView(FragmentTransaction fragmentTransaction , String problem , String machine){
problemViewFragment = new ProblemViewFragment(problem, machine);
fragmentTransaction.add(R.id.problemsLayout, problemViewFragment, "problemView");
}