【问题标题】:How to add RecyclerView in extended fragment to display the list如何在扩展片段中添加 RecyclerView 以显示列表
【发布时间】:2017-01-04 08:56:00
【问题描述】:

我在主要活动中扩展了 3 个片段。我如何添加 recyclerview 以在我的一个片段中显示列表。

请帮忙

【问题讨论】:

    标签: android android-fragments android-recyclerview


    【解决方案1】:

    没关系你是初学者:)。首先看看片段是如何工作的。片段需要一个活动。在活动中,您必须创建框架布局并在框架布局(活动)中加载或提交片段。

    现在,如果您想更改活动中的任何视图,您必须在片段中更改它并在更改其视图的活动中调用相应的片段。

    这意味着您必须在活动中添加recyclerview,但首先您必须将包含recyclerview 的片段添加到活动的框架布局中。

    【讨论】:

    • 你能提供一些相关的例子,我可以更好地理解,你提供的解释很好,但有些术语很难理解。
    • 是的,我知道片段对于初学者来说非常复杂。你在这里使用片段的目的是什么?您使用的是导航抽屉或选项卡还是其他任何东西??
    • 我将它用于标签(基本上 3 个标签)。我已将我的主要活动扩展到 3 个片段(3 个选项卡)..所以我想使用回收器视图和回收器适配器在片段之一中创建一个列表。
    【解决方案2】:

    你正在寻找这样的东西:

    注意:确保将其添加到您的应用程序 gradle:

    compile 'com.android.support:recyclerview-v7:23.4.0'
    

    你有fragment1.java 布局fragment1.xml: fragment1.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/fragment1_recycler_view"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:clickable="true">
                    </android.support.v7.widget.RecyclerView>
    </RelativeLayout>
    

    在 fragment1.java 中初始化这个 RecyclerView 并写入适配器。 有关更多信息,请尝试以下链接: How to implement RecyclerView with CardView rows in a Fragment with TabLayout http://www.androidhive.info/2016/01/android-working-with-recycler-view/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多