Created
February 29, 2016 22:53
-
-
Save tito/aedd9e1289b28f5bf2d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.config import Config | |
Config.set('modules', 'inspector', '') | |
# from _recycleview import RecycleView | |
from kivy.garden.recycleview import RecycleView | |
from kivy.base import runTouchApp | |
from kivy.lang import Builder | |
from kivy.app import App | |
KV = """ | |
<ContactItem@Label>: | |
canvas.before: | |
Color: | |
rgba: 1, 1, 1, 0.2 | |
Rectangle: | |
pos: self.pos | |
size: self.size | |
color: 0, 0, 0, 0.5 | |
BoxLayout: | |
orientation: "vertical" | |
BoxLayout: | |
size_hint_y: None | |
height: 30 | |
Button: | |
text: "fill" | |
on_release: app.generate_new_data() | |
Button: | |
text: "add" | |
on_release: app.add_item() | |
Button: | |
text: "clear" | |
on_release: app.clear_items() | |
Button: | |
text: "Remove first item" | |
on_release: app.remove_item() | |
Button: | |
text: "Update first item" | |
on_release: app.update_item() | |
RecycleView: | |
id: rv | |
key_viewclass: 'viewclass' | |
key_size: 'height' | |
""" | |
class RecycleViewApp(App): | |
def build(self): | |
return Builder.load_string(KV) | |
def update_item(self): | |
data = self.root.ids.rv.data[0] | |
data['text'] = 'test' | |
self.root.ids.rv.data[0] = data | |
def add_item(self): | |
data = self.root.ids.rv.data | |
for x in range(10): | |
data.insert(len(data), { | |
"viewclass": "ContactItem", | |
"text": 'x' + str(len(data))}) | |
def remove_item(self): | |
del self.root.ids.rv.data[0] | |
def clear_items(self): | |
del self.root.ids.rv.data[:] | |
def generate_new_data(self): | |
contacts = [] | |
for x in range(10): | |
contacts.append({ | |
"index": x, | |
"viewclass": "ContactItem", | |
"text": str(x)}) | |
self.root.ids.rv.data = contacts | |
RecycleViewApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment