抱歉,这个问题是为那些使用Eclipse并有访问ApiDemo示例代码权限的人准备的。具体来说,我正在尝试基于名为“FragmentLayout”的示例创建一个片段活动。
以下代码对我有问题(您可以在ApiDemo的“FragmentLayout.java”文件中找到完整代码,“ShowDetails()”方法):
以下代码对我有问题(您可以在ApiDemo的“FragmentLayout.java”文件中找到完整代码,“ShowDetails()”方法):
// Execute a transaction, replacing any existing fragment
// with this one inside the frame.
FragmentTransaction ft = getFragmentManager().beginTransaction();
if (index == 0) {
ft.replace(R.id.details, details);
} else {
ft.replace(R.id.a_item, details);
}
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
我有两个问题:
index == 0
和index != 0
之间有什么区别?资源R.id_a_item(在所有ApiDemos中只出现一次,在搜索之后)属于某种菜单快捷方式资源,不清楚为什么在这里使用。
Android开发者指南没有解释这段代码。
if( index==0 )
的东西可能会使应用程序挂起或删除内部 RAM :-) - ilomambo