How can I do the search
function depends on what I type in the textfield
? If the text I type in the textfield
is equal to the RecycleView data['name']
, how to make that only widget show?
KV = '''
<Card>:
AsyncImage:
source: root.source
ScreenManager:
id: screen_manager
screen_manager: screen_manager
Screen:
name: 'main'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Card List"
elevation: 10
pos_hint: {'top': 1}
MDIconButton:
icon: 'magnify'
pos_hint: {'center_y': .5}
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
on_release: root.screen_manager.current = 'search'
RecycleView:
id: rv
key_viewclass: 'viewclass'
RecycleGridLayout:
cols: 3
padding: dp(17), dp(20)
spacing: dp(15)
size_hint_y: None
height: self.minimum_height
default_size: dp(95), dp(135)
default_size_hint: None, None
orientation: 'vertical'
Screen:
name: 'search'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Search"
elevation: 10
pos_hint: {'top': 1}
MDIconButton:
icon: 'arrow-left'
pos_hint: {'center_y': .5}
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
on_release: root.screen_manager.current = root.screen_manager.previous()
ScrollView:
MDGridLayout:
cols: 1
padding: dp(20), dp(20)
spacing: dp(15)
size_hint_y: None
height: self.minimum_height
MDTextField:
id: search_field
hint_text: "Search"
icon_right: 'magnify'
MDRaisedButton:
text: "Search"
on_release: app.pressed()
'''
class Card(MDCard):
name = StringProperty()
source = StringProperty()
owner = ObjectProperty()
class Testing(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
with open('images.json') as f:
image_data = f.read()
images = json.loads(image_data)['PRD'].items()
self.root.ids.rv.data = [{'viewclass': "Card", 'name': k, 'source': v, 'owner': self} for k,v in images]
def pressed(self):
self.root.ids.search_field.text = ''