Android 显示相同内容的不同片段
我创建了一个包含三个片段的活动。第一个片段工作正常,第二个片段也正常,但第三个片段显示的内容与第二个片段相同 我看不出问题出在哪里,我有:(其中deletecase是第三个片段xml文件) 第二点:Android 显示相同内容的不同片段,android,android-fragments,Android,Android Fragments,我创建了一个包含三个片段的活动。第一个片段工作正常,第二个片段也正常,但第三个片段显示的内容与第二个片段相同 我看不出问题出在哪里,我有:(其中deletecase是第三个片段xml文件) 第二点: View rootView = inflater.inflate(R.layout.updatecase, container, false); 对于每个片段,我都有一个嵌套类 我怎样才能解决这个问题 编辑 我只是觉得我忘了做这个:p public Fragment getItem(int pos
View rootView = inflater.inflate(R.layout.updatecase, container, false);
对于每个片段,我都有一个嵌套类
我怎样才能解决这个问题
编辑
我只是觉得我忘了做这个:p
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a NewCaseFragment (defined as a static inner class
// below) with the page number as its lone argument.
if (position == 0) {
Fragment fragment = new NewCaseFragment();
// Bundle args = new Bundle();
// args.putInt(NewCaseFragment.ARG_SECTION_NUMBER, position +
// 1);
// fragment.setArguments(args);
return fragment;
} else if (position == 1){
Fragment fragment = new UpdateFragment();
return fragment;
}
else {
Fragment fragment = new DeleteFragment();
return fragment;
}
}
谢谢大家的回答。您是否验证了设计是否相同,但ID是否不同?主布局如何,即带有三个片段的布局。您确定第二个片段和第三个片段的android:name(或class)属性不同吗?这可能是R文件中的错误。尝试创建另一个布局并复制设计,以及片段中的引用。我看不到您在代码中的任何位置执行提交操作?这是创建默认片段活动时生成的SectionsPagerAdapter类中的方法,我只是忘了检查它:)
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a NewCaseFragment (defined as a static inner class
// below) with the page number as its lone argument.
if (position == 0) {
Fragment fragment = new NewCaseFragment();
// Bundle args = new Bundle();
// args.putInt(NewCaseFragment.ARG_SECTION_NUMBER, position +
// 1);
// fragment.setArguments(args);
return fragment;
} else if (position == 1){
Fragment fragment = new UpdateFragment();
return fragment;
}
else {
Fragment fragment = new DeleteFragment();
return fragment;
}
}