Kivy RecycleView custom labels

I’m creating an app with five screens.

  • On four screens the user can save different kind of data (number, string, list) to an sqlite3 database.
  • The fifth screen is the “History Screen” where the user can fetch the desired number of last elements from the database.

DB structure:

ListName Date Result1 Result1
DataInput 15/06/2024 85 None
DataInput 15/06/2024 1, 2, 3 10, 11
DataInput 15/06/2024 Python None

On the History Screen I use RecycleView. It works but I want to improve it a bit. Unfortunately I’m stuck.

RecycleView now:

What I want to achive: to create a custom label for DataInput, Date, Result1, Result2 (and maybe a divider between the list name and the last number)

What I’ve tried so far: create a custom viewclass. The problem here is that I don’t know how to populate the custom labels and achive the same result as you see in the picture above but with custom labels. I found similar questions here on stackoverflow but I still can’t figure it out how to solve it.

Viewclass example:

<CustomView@BoxLayout>:
    value_listname: ""
    value_date: ""
    value_result1: ""
    value_result2: ""

    BoxLayout:
        orientation: "vertical"
        Label:
            text: root.value_listname
            color: 1, 1, 0, 1
            font_size: "13sp"
        Label:
            text: root.value_date
            color: 1, 0, 1, 1
        Label:
            text: root.value_result1
        Label:
            text: root.value_result2
        
        #Divider after the last number

Example code:

from kivy.app import App
from kivy.lang import Builder
import sqlite3
import random
import datetime

from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.properties import ObjectProperty, ListProperty

Builder.load_string("""
<CustomView@BoxLayout>:
    value_listname: ""
    value_date: ""
    value_result1: ""
    value_result2: ""

    BoxLayout:
        orientation: "vertical"
        Label:
            text: root.value_listname
            color: 1, 1, 0, 1
            font_size: "13sp"
        Label:
            text: root.value_date
            color: 1, 0, 1, 1
        Label:
            text: root.value_result1
        Label:
            text: root.value_result2
        
        #Divider after the last element


<DataInputScreen>:
    number_1: number_1
    number_2: number_2
    result: result
    
    BoxLayout:
        orientation: "vertical"
        
        TextInput:
            id: number_1
            
            hint_text: "from... (int)"
            halign: "center"
            font_size: "50dp"
            size_hint: 1, 0.5
            
        TextInput:
            id: number_2
            
            hint_text: "...to (int)"
            halign: "center"
            font_size: "50dp"
            size_hint: 1, 0.5
            
        Label:
            id: result
            
            font_size: "50dp"
            
        Button:
            text: "Show the number and save it to DB"
            
            on_release:
                root.random_choice()
                
        Button:
            text: "Go to 'History' screen"
            
            on_release:
                app.root.current = "historyscreen"
                
                
<HistoryScreen>:
    record_text: record_text            
    
    BoxLayout:
        orientation: "vertical"
        
        TextInput:
            id: record_text
            
            hint_text: "Show the last 'n' record(s)"
            halign: "center"
            font_size: "50dp"
            size_hint: 1, 0.2       
                        
        Button:
            text: "Show the records from DB"
            size_hint: 1, 0.2
            
            on_release:
                root.show_records()
               
        Button:
            text: "Back to 'DataInput' screen"
            size_hint: 1, 0.2
            
            on_release:
                app.root.current = "datainput"    
                
        BoxLayout:
            size_hint: 1, 0.600
            pos_hint: {"center_x": 0.500, "center_y": 0.350}
            RecycleView:
                id: rv
                viewclass: "Label"
                #viewclass: "CustomView"
                RecycleBoxLayout:
                    default_size: None, dp(30)
                    default_size_hint: 1, None
                    size_hint_y: None
                    height: self.minimum_height
                    orientation: 'vertical'                   
                
    """
                    )


class DataInputScreen(Screen):
    number_1 = ObjectProperty()
    number_2 = ObjectProperty()
    result = ObjectProperty()


    def random_choice(self):
        first_number = int(self.number_1.text)
        second_number = int(self.number_2.text)

        if first_number > second_number:
            first_number, second_number = second_number, first_number

        x = random.randint(first_number, second_number)

        self.result.text = str(x)

        conn = sqlite3.connect("results.db")
        c = conn.cursor()
        c.execute("INSERT INTO numbers VALUES (:ListName, :Date, :Result1, :Result2)",
                  {
                      "ListName": "DataInput",
                      "Date": datetime.datetime.now(),
                      "Result1": self.result.text,
                      "Result2": None})
        conn.commit()
        conn.close()


class HistoryScreen(Screen):
    record_text = ObjectProperty()
    data_items = ListProperty([])

    def show_records(self):
        self.data_items = ""

        conn = sqlite3.connect("results.db")
        c = conn.cursor()
        c.execute("SELECT Date, ListName, Result1, Result2 FROM numbers LIMIT ?", (self.record_text.text,))
        records = c.fetchall()
        conn.commit()
        conn.close()

        for record in filter(None, records):
            for col in filter(None, record):
                self.data_items.append(col)

        self.ids.rv.data = [{'text': str(x)} for x in self.data_items]

class myApp(App):
    def build(self):
        sm = ScreenManager(transition=NoTransition())
        sm.add_widget(DataInputScreen(name="datainput"))
        sm.add_widget(HistoryScreen(name="historyscreen"))

        """Create Database"""
        conn = sqlite3.connect("results.db")
        c = conn.cursor()
        c.execute("""CREATE TABLE if not exists numbers(
        Date text,
        ListName text,       
        Result1 text,           
        Result2 text
        )
        """)
        conn.commit()
        conn.close()

        return sm

myApp().run()

Could you help me?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật