0

I'm brushing up on my Fragments knowledge following the official tutorial from android developers website; there is a statement into the demo code that doesn't sound clear to me

FragmentTransaction ft = getFragmentManager().beginTransaction();
if (index == 0) {
    ft.replace(R.id.details, details);
} else {
    ft.replace(R.id.a_item, details);
}

I think I can understand the logic behind the code, but can't figure out where is that item with id = a_item; it doesn't seem to be declared anywhere and obviously the demo app doesn't work.

Can you help me to better understand that piece of code? Thanks in advance

4

1 回答 1

0
  • R.id.detailsViewGroup您要在其中插入片段(或替换片段)的内部。

  • details指应该插入/替换的片段的实例ViewGroup

笔记:

  • 不要忘记打电话transaction.commit()给实际

  • 这不适用于使用片段标记直接插入 XML 的片段。您只能替换从 Java 代码中插入的片段。

于 2013-11-05T20:01:21.217 回答