动态添加fragment之后,其他布局莫名不显示问题之控件id大乌龙!!!!

 

下面是动态添加fragment代码,添加fragment之后其他布局莫名隐藏

private void initSelf() {
        FragmentManager fragmentManager = getSupportFragmentManager();

        //开启事务
        FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
        PolicePlatformFragment fragment1 = new PolicePlatformFragment();
        Bundle bundle1 = new Bundle();
        bundle1.putStringArrayList("data", (ArrayList<String>) policeTj);
        bundle1.putSerializable("dzf", dzfData);
        fragment1.setArguments(bundle1);
        beginTransaction = beginTransaction.replace(android.R.id.content, fragment1);
        beginTransaction.commit();
    }

最后发现,是这一行的

beginTransaction = beginTransaction.replace(android.R.id.content, fragment1);

 

android.R.id.content

搞得鬼,容器的id等同于安卓系统的id造成的,改成

R.id.content

问题解决。

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐