简体   繁体   English

如何从两个表中获取数据的回收视图?

[英]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.

相关问题 如何使用两个或多个表中的数据加载RecyclerView SQLite - How to load a RecyclerView with data from two or more tables SQLite 如何在Hibernate中使用联接从两个表中获取JSON数据? - How do I get JSON data from two tables using joins in Hibernate? 我如何使用来自 firebase 的数据制作可点击的 recyclerview - how do i make a recyclerview with data from firebase clickable with an intent 如何在数组中交换两个整数,而我的方法从main中获取两个整数和一个数组? - How do I swap two integers in an array, where my method takes in two integers and an array from main? 如何在Spring Boot JPA中从两个表中获取数据 - How do I get data from two tables in spring boot jpa 如何调用从Java获取二维数组字符串的Clojure函数? - How do I call a Clojure function that takes a two-dimensional array of Strings from Java? 如何在RecyclerView中异步加载数据? - How do I load data in RecyclerView asynchronously? 我如何从查询中的两个表中获取数据? - How i can get data from two tables in on query? 我如何从两个不同的表中获取数据 - How can i get data from two different tables 如何使用 Hibernate 从两个单独的表中只返回两个字段? - How do I return only two fields from two separate tables using Hibernate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM