J
The class that acts as a row must inherit kivy.uix.recycleview.views.RecycleDataViewBehavior, done this you can use the method refresh_view_attrs to assign the values.On the other hand the height of RecycleBoxLayout must be the minimum to contain items or it will be impossible to scrooll, you need to add the following values to these properties:size_hint_y: None
height: self.minimum_height
A basic example would be:import json
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.recycleview.views import RecycleDataViewBehavior
esta funcion nos devolvera el valor del json
def sacar_nombres():
with open('data/centros.json') as f:
places = json.load(f)
return places
items = sacar_nombres()
KV = '''
<CenterViewRow>:
cols: 2
labelid_text: ''
entryname_text: ''
TextInput:
id: id_entryname
text: root.entryname_text
Label:
id: id_labelid
text: root.labelid_text
RecycleView:
data: []
viewclass: 'CenterViewRow'
RecycleBoxLayout:
default_size_hint: 1, None
default_heigth: 100
orientation: 'vertical'
size_hint_y: None
height: self.minimum_height
'''
class CenterViewRow(RecycleDataViewBehavior, GridLayout):
def refresh_view_attrs(self, rv, index, data):
self.entryname_text = data['entryname']
self.labelid_text = data['labelid']
return super().refresh_view_attrs(
rv, index, data)
class Test(App):
def build(self):
root = Builder.load_string(KV)
root.data= [
{'entryname': item["id"],
'labelid': item["centro"]}
for item in items]
print(root.data)
return root
Test().run()
Like test JSON:[{"id": "1", "nombre": "Centro A"},
{"id": "2", "nombre": "Centro B"},
{"id": "3", "nombre": "Centro C"}]