java - 显示具有相同类型适配器的多个 RecyclerView
问题描述
我试图在同一个片段中显示 3 个 RecyclerView,每个 RecyclerView 显示不同类型的匹配(已完成匹配、本周匹配和尚未匹配)。
我已经实例化了 3 个 RV 和 3 个适配器,如下面的代码所示:
matchesList_rv_finished = view.findViewById(R.id.finished_upcoming_matches_rv);
matchesList_rv_finished.setHasFixedSize(true);
LinearLayoutManager layoutManager1 = new LinearLayoutManager(view.getContext(), LinearLayoutManager.HORIZONTAL, false);
matchesList_rv_finished.setLayoutManager(layoutManager1);
matchesList_rv_Week = view.findViewById(R.id.Week_upcoming_matches_rv);
matchesList_rv_Week.setHasFixedSize(true);
LinearLayoutManager layoutManager2 = new LinearLayoutManager(view.getContext(), LinearLayoutManager.HORIZONTAL, false);
matchesList_rv_Week.setLayoutManager(layoutManager2);
matchesList_rv_NotYet = view.findViewById(R.id.NotYet_upcoming_matches_rv);
matchesList_rv_NotYet.setHasFixedSize(true);
LinearLayoutManager layoutManager3 = new LinearLayoutManager(view.getContext(), LinearLayoutManager.HORIZONTAL, false);
matchesList_rv_NotYet.setLayoutManager(layoutManager3);
matchAdapter1 = new MatchAdapter();
matchAdapter2 = new MatchAdapter();
matchAdapter3 = new MatchAdapter();
这就是我接收 3 个匹配列表并设置 3 个适配器的方式:
Model.instance.getUpComingMatches(new Model.MatchListener() {
@Override
public void onComplete(ArrayList<Match> finishedMatches,
ArrayList<Match> thisWeekMatches,
ArrayList<Match> notYetMatches) {
finishedMatchList = finishedMatches;
matchAdapter1.setMatchesData(finishedMatchList);
matchesList_rv_finished.setAdapter(matchAdapter1);
ThisWeekMatchList = thisWeekMatches;
matchAdapter2.setMatchesData(ThisWeekMatchList);
matchesList_rv_Week.setAdapter(matchAdapter2);
NotYetMatchList = notYetMatches;
matchAdapter3.setMatchesData(NotYetMatchList);
matchesList_rv_NotYet.setAdapter(matchAdapter3);
}
});
我不确定我做错了什么,但似乎最后一个适配器覆盖了前 2 个适配器的数据,而不是在每个 RV 中显示 3 个不同的匹配项:
我想我在这里缺少一些基本信息,或者也许只有一种更简单的方法来实现这一点?谢谢您的帮助!
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/upcoming_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UpcomingMatchesFragment" >
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/Week_upcoming_matches_rv"
android:layout_width="382dp"
android:layout_height="167dp"
android:layout_marginStart="16dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/finished_upcoming_matches_rv"
android:layout_width="382dp"
android:layout_height="167dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/NotYet_upcoming_matches_rv" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/NotYet_upcoming_matches_rv"
android:layout_width="382dp"
android:layout_height="167dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Week_upcoming_matches_rv" />
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
这项技术已经存在于 Sport365 和 onefootball 等应用程序中。我有同样的问题
推荐阅读
- java - 仅当在 Scala 中使用不相关的对象时才同步块
- math - 在 OBB(定向边界框)上查找特定点
- sql - SQL 更新列
- sql-server - 提高查询性能
- python - 我正在尝试重新调整与 MinMaxscaler 方法略有不同的数据框中的数字列
- python - Fail to load a subpart of "open-images-v6" with Fiftyone
- java - 数组列表未成功打印
- redis - 如何调试内存使用量超过 20GB 的 redis?
- swift - 如何在不覆盖其他节点的情况下更新 Firebase 中的子节点
- sql-server - ODBC for MSSQL v17 错误 - 架构 sys 的表名 syscharsets 无效