我的onCreateVIEw方法有一个小问题-给定的容器/父级为null,因此我无法膨胀我的布局.这是我的代码:
这是我的“主要”课程
public class DrawerActivity extends ActionBaractivity implements NavigationFragment.NavigationListener { private static final int DRAWER_DELAY = 250; private Toolbar toolbar; private NavigationFragment navigationFragment; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // check if smartphone or tablet... if (isstaticmenuDrawer()) { setContentVIEw(R.layout.activity_drawer_static); } else { setContentVIEw(R.layout.activity_drawer); } } protected voID createMenuDrawer(int contentVIEwID) { VIEwGroup content = (VIEwGroup) findVIEwByID(R.ID.content); content.addVIEw(getLayoutInflater().inflate(contentVIEwID, null)); navigationFragment = (NavigationFragment) getSupportFragmentManager().findFragmentByID(R.ID.drawer_fragment); navigationFragment.initDrawer(R.ID.drawer_fragment, R.ID.drawer_layout, toolbar); }}
这是我的activity_drawer.xml
<?xml version="1.0" enCoding="utf-8"?><androID.support.v4.Widget.DrawerLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/drawer_layout" androID:layout_height="match_parent" androID:layout_wIDth="match_parent" > <FrameLayout androID:ID="@+ID/content" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"/> <include layout="@layout/include_drawer"/> <include layout="@layout/include_toolbar"/></androID.support.v4.Widget.DrawerLayout>
这是我的OvervIEwActivity(我的启动器/默认活动)
public class OvervIEwActivity extends DrawerActivity { OvervIEwFragment overvIEw; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); createMenuDrawer(R.layout.activity_overvIEw); }}
我的activity_overvIEw.xml
<?xml version="1.0" enCoding="utf-8"?><fragment xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:ID="@+ID/fragment_overvIEw" />
还有…我的片段
public class OvervIEwFragment extends Fragment { @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater, @Nullable VIEwGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_overvIEw, container, false); }}
谁能解释我,为什么容器为空?谢谢… :)
解决方法:
您的< fragment>使用静态方法时,需要将其包含在视图组中.只需将relativeLayout作为它的父项放在XML文件中即可.
总结以上是内存溢出为你收集整理的Android Fragment-onCreateView-容器为空全部内容,希望文章能够帮你解决Android Fragment-onCreateView-容器为空所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)