Skip to content

Instantly share code, notes, and snippets.

@VICTORVICKIE
Created June 1, 2021 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VICTORVICKIE/34b6904d7c246d5ac283b2b7593c9730 to your computer and use it in GitHub Desktop.
Save VICTORVICKIE/34b6904d7c246d5ac283b2b7593c9730 to your computer and use it in GitHub Desktop.
Kivy Advanced RecycleView
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
from kivy.properties import StringProperty
from kivy.uix.boxlayout import BoxLayout
from kivymd.theming import ThemableBehavior
from kivymd.uix.behaviors import RectangularRippleBehavior
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.floatlayout import FloatLayout
from kivymd.uix.screen import MDScreen
Builder.load_string('''
<Label>:
color: 0, 0, 0, 1
<SearchResults>:
AnchorLayout:
anchor_x : "right"
BoxLayout:
Label:
id: area_lbl
color: 0, 0, 0, 0.75
text: root.area
size_hint_x: None
width: 1.5 * self.texture_size[0]
MDIcon:
id: chevron_icon
theme_text_color: "Custom"
text_color: 0, 0, 0, 0.5
icon: "chevron-right"
size_hint_x: None
width: self.texture_size[0]
Label:
id: shop_lbl
text: root.shop
size_hint_x: None
width: 1.5 * self.texture_size[0]
Label:
size_hint_x: None
width: 1.5 * self.texture_size[0]
text: "\u20B9" + " " + root.balance
<SearchRV>:
key_viewclass: "viewclass"
key_size: "height"
RecycleBoxLayout:
padding: "10dp"
default_size: None, dp(58)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: "vertical"
''')
class SearchResults(ThemableBehavior, RectangularRippleBehavior, ButtonBehavior, BoxLayout):
area = StringProperty()
shop = StringProperty()
balance = StringProperty()
class SearchRV(RecycleView):
def __init__(self,**kwargs):
super().__init__(**kwargs)
self.data = []
for num in range(1,101):
self.add_data(num)
def add_data(self, num):
self.data.append({
"viewclass": "SearchResults",
"area": f"area {num}",
"shop": f"shop {num}",
"balance": str(num)
})
class TestApp(MDApp):
def build(self):
screen = MDScreen(name="RV")
rv = SearchRV()
screen.add_widget(rv)
return screen
if __name__ == '__main__':
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment