我想要在片段上设置默认框架布局,并且此框架布局显示在半布局的顶部,剩余的一半包含列表view.frame布局更新布局项目单击列表项时这些都工作正常。但是当我想设置默认框架布局时,从前面的活动来,然后它会创建问题。这是我如何打开我的片段,这是我的适配器类从此活动。我想在下一个包含列表的活动上设置默认的框架布局。是否有可能从另一个活动同时调用活动和片段
grid.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// Get the position
resultp = data.get(position);
frame=(FrameLayout)grid.findViewById(R.id.fragment_container);
Intent intent = new Intent(context, SingleItemView.class);
intent.putExtra("id", resultp.get(MainActivity.RANK));
intent.putExtra("count", resultp.get(MainActivity.COUNTRY));
intent.putExtra("population",resultp.get(MainActivity.POPULATION));
intent.putExtra("flag", resultp.get(MainActivity.FLAG));
// Start SingleItemView Class
intent.putExtra("mylist", data);
context.startActivity(intent);
if(frame==null){
DefaultLogFrag fragment1 = new DefaultLogFrag();
FragmentManager fragmentManager1 = ((Activity) context).getFragmentManager();
FragmentTransaction fragmentTransaction1 = fragmentManager1.beginTransaction();
fragmentTransaction1.add(R.id.fragment_container, fragment1);
fragmentTransaction1.commit();
}
}
});
您应该添加在'的onCreate片段()''的活动SingleItemView'感谢 –