最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Adding a new MDList to an MDListItem in KivyMD - Stack Overflow

programmeradmin0浏览0评论

if someone could help me, I have an MDList created in a kivy file and I populate it dynanically. When an Item is clicked I would like to insert to that Item a new MDList with the data of the DB.

I tried several things and searched on google but nothing.

This is my code:

class HomeScreen(MDScreen):
def __init__(self, db, **kwargs):
    super(HomeScreen, self).__init__(**kwargs)
    self._fill_list(db)

def _fill_list(self, db) -> None:
    ''' Fill each letter list item with the number of contacts
        parameter db -> is the database with the clients contacts
    '''
    for item in range(65, 91): # 65 ascii code for 'a' and 90 for 'z'
        sql = f"SELECT count(*) FROM clients WHERE name LIKE '{chr(item)}%'"

        letters_item = MDListItem(
            MDListItemHeadlineText(text=chr(item)), 
            MDListItemSupportingText(text=f'{db.get_count(sql)} contacts'),
            MDListItemTrailingIcon(icon='account'),
            on_release= lambda item: self._letter_sublist(item),
        )

        self.ids.list_letters.add_widget(letters_item)

def _letter_sublist(self, item: MDListItem) -> None:
    letter_list = MDList()

    for i in range(0, 3):
        item = MDListItem(
            MDListItemHeadlineText(text='Name'), 
            MDListItemSupportingText(text='Phone'),
        )
        letter_list.add_widget(item)

    item.add_widget(letter_list)
发布评论

评论列表(0)

  1. 暂无评论