失败:刷新 RecycleView 数据
Kivy: refresh RecycleView data
我看到不同的帖子都在谈论这个: and THERE。
但是当我只想了解进行更改的确切行是什么时,它们是复杂的解决方案。我可以访问 RecycleView
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.factory import Factory as F
from kivy.properties import ListProperty
KV = '''
<Item>:
RecycleView:
data: app.data
viewclass: 'Row'
RecycleBoxLayout:
id: recycle_view
orientation: 'vertical'
size_hint: 1, None
height: self.minimum_height
default_size_hint: 1, None
default_size: 0, dp(40)
'''
def _on_text(instance, value):
recycle_view = instance.app.screen.ids["recycle_view"]
print(recycle_view,"value that I want to update in the recycle_view:",value)
#recycle_view.data ? I don't know how to access the data and change it !
class Row(F.TextInput):
def on_kv_post(self, base_widget):
super().on_kv_post(base_widget)
self.app = MDApp.get_running_app()
self.bind(text=_on_text)
class Application(MDApp):
data = ListProperty()
def build(self):
self.data = [
{'index': i, 'text': 'hello {}'.format(i)}
for i in range(40)
]
self.screen = Builder.load_string(KV)
return self.screen
if __name__ == "__main__":
Application().run()
好吧,我发现我错过了我在玩 RecycleBoxlaout
而不是 RecycleView
的事实。
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.factory import Factory as F
from kivy.properties import ListProperty
KV = '''
<Item>:
RecycleView:
data: app.data
viewclass: 'Row'
RecycleBoxLayout:
id: recycle_boxlayout
orientation: 'vertical'
size_hint: 1, None
height: self.minimum_height
default_size_hint: 1, None
default_size: 0, dp(40)
'''
def _on_text(instance, value):
instance.app.screen.data[instance.index]["text"] = value
class Row(F.TextInput):
def on_kv_post(self, base_widget):
super().on_kv_post(base_widget)
self.app = MDApp.get_running_app()
self.counter = -1
self.bind(text=_on_text)
class Application(MDApp):
data = ListProperty()
def build(self):
self.data = [
{'index': i, 'text': 'hello {}'.format(i)}
for i in range(40)
]
self.screen = Builder.load_string(KV)
return self.screen
if __name__ == "__main__":
Application().run()
我看到不同的帖子都在谈论这个:
但是当我只想了解进行更改的确切行是什么时,它们是复杂的解决方案。我可以访问 RecycleView
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.factory import Factory as F
from kivy.properties import ListProperty
KV = '''
<Item>:
RecycleView:
data: app.data
viewclass: 'Row'
RecycleBoxLayout:
id: recycle_view
orientation: 'vertical'
size_hint: 1, None
height: self.minimum_height
default_size_hint: 1, None
default_size: 0, dp(40)
'''
def _on_text(instance, value):
recycle_view = instance.app.screen.ids["recycle_view"]
print(recycle_view,"value that I want to update in the recycle_view:",value)
#recycle_view.data ? I don't know how to access the data and change it !
class Row(F.TextInput):
def on_kv_post(self, base_widget):
super().on_kv_post(base_widget)
self.app = MDApp.get_running_app()
self.bind(text=_on_text)
class Application(MDApp):
data = ListProperty()
def build(self):
self.data = [
{'index': i, 'text': 'hello {}'.format(i)}
for i in range(40)
]
self.screen = Builder.load_string(KV)
return self.screen
if __name__ == "__main__":
Application().run()
好吧,我发现我错过了我在玩 RecycleBoxlaout
而不是 RecycleView
的事实。
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.factory import Factory as F
from kivy.properties import ListProperty
KV = '''
<Item>:
RecycleView:
data: app.data
viewclass: 'Row'
RecycleBoxLayout:
id: recycle_boxlayout
orientation: 'vertical'
size_hint: 1, None
height: self.minimum_height
default_size_hint: 1, None
default_size: 0, dp(40)
'''
def _on_text(instance, value):
instance.app.screen.data[instance.index]["text"] = value
class Row(F.TextInput):
def on_kv_post(self, base_widget):
super().on_kv_post(base_widget)
self.app = MDApp.get_running_app()
self.counter = -1
self.bind(text=_on_text)
class Application(MDApp):
data = ListProperty()
def build(self):
self.data = [
{'index': i, 'text': 'hello {}'.format(i)}
for i in range(40)
]
self.screen = Builder.load_string(KV)
return self.screen
if __name__ == "__main__":
Application().run()