[英]How do I poblate a recyclerview that takes data from two tables?
I'm working on a recyclerview that has two textViews inside.我正在开发一个内部有两个 textViews 的 recyclerview。
One goes for the hour placed on one table And the other one goes for the medicine name that's connected as a foreign key via id.一个用于放置在一张桌子上的小时,另一个用于通过 id 作为外键连接的药物名称。
Thing is, how can I actually call those?问题是,我怎么能真正称呼那些? I can't get two adapters in one RecyclerView, so how can I deal with this?
我无法在一个 RecyclerView 中获得两个适配器,那么我该如何处理呢?
This is the item that I use for poblating the recyclerview:这是我用于对 recyclerview 进行更新的项目:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/manzana_semi"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewH"
android:layout_width="21dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingTop="2dp"
android:text="TextView"
android:textColor="@color/verde_junta" />
<TextView
android:id="@+id/medTextView"
android:layout_width="202dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="15dp"
android:paddingTop="2dp"
android:text="TextView"
android:textColor="@color/verde_junta" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="30dp"
android:scaleType="fitEnd"
app:srcCompat="@drawable/ic_remove" />
</LinearLayout>
</RelativeLayout>
Define an object that holds both the hour and the medicine like定义一个 object 来保存小时和药物,如
class DataHolder{
String hour;
String Medicine;
}
in your recyclerview adapter let it take a list of this object to populate its views.在您的 recyclerview 适配器中,让它获取此 object 的列表以填充其视图。
in your activity/fragment get data from your 2 different data sources and create objects of this type then populate your recyclerview在您的活动/片段中从您的 2 个不同数据源获取数据并创建这种类型的对象,然后填充您的 recyclerview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.