【发布时间】:2017-01-04 08:56:00
【问题描述】:
我在主要活动中扩展了 3 个片段。我如何添加 recyclerview 以在我的一个片段中显示列表。
请帮忙
【问题讨论】:
标签: android android-fragments android-recyclerview
我在主要活动中扩展了 3 个片段。我如何添加 recyclerview 以在我的一个片段中显示列表。
请帮忙
【问题讨论】:
标签: android android-fragments android-recyclerview
没关系你是初学者:)。首先看看片段是如何工作的。片段需要一个活动。在活动中,您必须创建框架布局并在框架布局(活动)中加载或提交片段。
现在,如果您想更改活动中的任何视图,您必须在片段中更改它并在更改其视图的活动中调用相应的片段。
这意味着您必须在活动中添加recyclerview,但首先您必须将包含recyclerview 的片段添加到活动的框架布局中。
【讨论】:
你正在寻找这样的东西:
注意:确保将其添加到您的应用程序 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/
【讨论】: