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)