我有一个其中包含4个片段的应用程序。第一次,我总是创建每个片段,第一次,每个片段都可以正常加载,但是当我第二次返回该片段时,我将隐藏先前的片段并显示该特定片段。但是当我展示片段时。它显示白色的空白屏幕。我检查了fragmnet.getView返回的是null。
public void show_fragment(String fargemnt_tag)
{
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
FragmentManager fragmentManager = getSupportFragmentManager();
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
try
{
Fragment lastFragment = fragmentManager.findFragmentByTag(common.last_fragment_tag);
if(lastFragment!=null)
{
fragmentManager.beginTransaction().hide(lastFragment).commit();
}
Fragment fragmentA = fragmentManager.findFragmentByTag(fargemnt_tag);
if (fragmentA!=null)
{
ft.show(fragmentA).commit();
}
else
{
if(fargemnt_tag.equals("masterPlanFragment"))
{
getSupportFragmentManager().beginTransaction().replace(R.id.mainContainter_fragment,masterPlanFragment,fargemnt_tag).commit();
}
else if(fargemnt_tag.equals("officesFragment"))
{
officesFragment = new OfficesFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.mainContainter_fragment,officesFragment,fargemnt_tag).commit();
}
else if(fargemnt_tag.equals("connectivityFragment"))
{
connectivityFragment = new ConnectivityFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.mainContainter_fragment, connectivityFragment,fargemnt_tag).commit();
}
else if(fargemnt_tag.equals("londonRoyalDocksFragment"))
{
londonRoyalDocksFragment = new LondonRoyalDocksFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.mainContainter_fragment,londonRoyalDocksFragment,fargemnt_tag).commit();
}
else if(fargemnt_tag.equals("videosFragment"))
{
videosFragment = new VideosFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.mainContainter_fragment,videosFragment).commit();
}
else
{
projectTeamFragment = new ProjectTeamFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.mainContainter_fragment,projectTeamFragment,fargemnt_tag).commit();
}
}
common.last_fragment_tag=fargemnt_tag;
} catch (Exception e) {
e.printStackTrace();
}
}