0

我看到不同的帖子在谈论这个:HERETHE

但是当我只想了解进行更改的确切线路是什么时,它们是复杂的解决方案。我可以访问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()
4

1 回答 1

0

好吧,我发现我错过了我正在玩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()
于 2021-08-12T14:08:51.857 回答