我从服务器获取数据,有没有办法在不创建文件夹菜单的情况下将项目添加到NavigationView并将项目放入xml文件中?
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="********">
<FrameLayout
android:id="@+id/ContentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/DrawerNavView"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="end"
android:fitsSystemWindows="true" />
</android.support.v4.widget.DrawerLayout>
MainActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerNavView = (NavigationView) findViewById(R.id.DrawerNavView);
上面的代码使应用程序崩溃。