3

我正在努力解决片段的结构,事情是......在活动中有两个片段。一个包含一个列表。打电话给这个FragmentA。另一个包含细节。打电话给这个FragmentB

中的每个列表项FragmentA都有不同的视图FragmentB,那么处理这种情况的首选方法是什么?

谢谢你

4

1 回答 1

3

在没有看到相关应用程序的复杂性的情况下,我建议每个不同的视图FragmentB都在其自己的片段中表示。

根据您R.id.fragment_container在. 像这样的东西:FragmentBFragmentA

// Create new fragment and transaction
Fragment newFragment = new ExampleFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();

// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);

// Commit the transaction
transaction.commit();
于 2012-06-04T07:10:23.547 回答