[英]How can I add a fragment inside view pager framgent
I am using a view pager .It contains three fragments. 我正在使用视图分页器。它包含三个片段。 I need to add fragment on one of the view pager fragments when button clicked but I am having a problem in doing that. 单击按钮时,我需要在视图分页器片段之一上添加片段,但是这样做有问题。
this is the java code that should opens the new fragment but there is something wrong in it 这是应该打开新片段的Java代码,但其中存在错误
Toast.makeText(context, "clicked", Toast.LENGTH_SHORT).show();
Bundle lessonData = new Bundle();
LessonContent lessonContent = new LessonContent();
lessonData.putString("lessonTitle", mylist.getTitle());
lessonData.putString("lessonContent", mylist.getContent());
lessonContent.setArguments(lessonData);
((Activity) context).getFragmentManager().beginTransaction()
.add(lessonContent, null)//I think this line is wrong
.addToBackStack(null)
.commit();
.add(lessonContent, null)//I think this line is wrong
Should probably replace by: 应该替换为:
.replace(R.id.yourfragmentcontainerid, lessonContent) // or android.R.id.content
And then it should work. 然后它应该工作。 The point is, it's not getting the layout to show so, it does not show anything. 关键是,它没有使布局显示出来,因此,它什么都不显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.