samedi 7 mars 2015

Android: Navigation/hamburger menu won't open after adding RecyclerView



My end goal is to create a simple material designed todo list. I'm only in the early stages, but I've hit an issue I can't seem to get through. When I add the recycler view to the main activity, the navigation menu won't show when I swipe from the left, or when I hit the hamburger menu. When I comment it out, it works fine. Does anyone know what the issue could be? I'm pretty sure it's something simple, but I've researched online and here on StackOverflow, and can't seem to come up with an answer. You all have been so helpful in the past, I'm hoping some magic can happen again!


I'm following the tutorial series here with a minor adjustment starting in video #6, where I want the recycler view in the main activity, instead of the navigation drawer: http://ift.tt/1NveEbo


Here's the entire code: http://ift.tt/1MfYyi9


The specific files in question are here: http://ift.tt/1NveEbp (tagged "// Setup tasks", currently lines 40-43)


http://ift.tt/1MfYvTz (tagged "", currently lines 45-50)


Thanks!


Here is the layout in question:



<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_height="match_parent"
android:layout_width="match_parent" >

<!-- Navigation Drawer -->
<LinearLayout
android:id="@+id/drawer_layout_overall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<!-- Include app_bar so the bar shows after drawer is opened -->
<include
android:id="@+id/app_bar"
layout="@layout/app_bar" />

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<fragment
android:id="@+id/fragment_navigation_drawer"
android:name="cca.habitrpgnativeclient.com.NavigationDrawerFragment"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>



</LinearLayout>

<!-- Tasks -->
<!--<android.support.v7.widget.RecyclerView-->
<!--android:id="@+id/tasks_layout"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:paddingTop="@dimen/app_bar_top_padding"-->
<!--android:paddingLeft="@dimen/tasks_left_padding" />-->

</RelativeLayout>


Also, here is the method in question:



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Setup toolbar
toolbar= (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

// Setup navigation menu
NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(((DrawerLayout) findViewById(R.id.drawer_layout)), toolbar);

// Setup tasks
// recyclerView = (RecyclerView) findViewById(R.id.tasks_layout);
// taskAdapter = new TaskAdapter(this, getTasks());
// recyclerView.setAdapter(taskAdapter);
// recyclerView.setLayoutManager(new LinearLayoutManager(this));

}


(Thanks for the edit, I added the other method as well)




Aucun commentaire:

Enregistrer un commentaire