简体   繁体   English

如何在Android中添加RecyclerView导航?

[英]How to add a RecyclerView to Navigation in Android?

I am working on task managing app on Android and would like users be able to click "+" button in navigation so that they can add a new project whenever they need and in such way that a new project appears in navigation immediately that can be used to access only tasks of this project. 我正在开发Android上的任务管理应用程序,并希望用户能够点击导航中的“+”按钮,以便他们可以在需要时添加新项目,以便新项目立即出现在导航中,可以使用仅访问此项目的任务。

I wanted to do this using a RecyclerView and adapter to fill items in navigation, but this didn't work out. 我想使用RecyclerView和适配器来填充导航中的项目,但这没有用。

Can you tell me how should I implement this using a RecyclerView or something else? 你能告诉我应该如何使用RecyclerView或其他东西来实现它? An example of how I would like it to look like is from Google Task 我希望它看起来像一个例子来自Google Task

Add RecyclerView inside NavigationView and Add your task list into RecyclerView. 在NavigationView中添加RecyclerView并将任务列表添加到RecyclerView中。 You can easily perform click Item click of RecyclerView. 您可以轻松执行RecyclerView的单击项目单击。

<android.support.design.widget.NavigationView
    android:id="@+id/navigationView"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/navigationList"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.NavigationView>

Note: When you click item of RecyclerView you must close NavigationDrawer. 注意:单击RecyclerView项时,必须关闭NavigationDrawer。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM