title: How to change text in TextInput field after a user picks a label from RecycleView
body: <p>I am developing a transportation app using Kivy and Python. There is a TextInput field where the user starts typing the name of a departure stop. On text input, a RecycleView with selectable departure stops names will be displayed. After the user clicks on a departure stop name, the name of the departure stop should be copied to the TextInput field and the RecycleView should disappear until the user starts typing in the field again.</p>
  
  <p>Right now, <strong>I don't know how to copy the departure stop name chosen by the user within the RecycleView to the text input field.</strong></p>
  
  <p>A sample of search_trip.kv:</p>
  
  <pre><code>&lt;MatchedStops&gt;:
      orientation: "vertical"
  
      DepartureStopName:
          id: departure_stop
          hint_text: "Departure stop"
          multiline: False
          on_text:
              root.find_stop(departure_stop.text)
  
      RecycleView:
          viewclass: 'SelectableLabel'
          data: [{'text': str(x["stop_name"])} for x in root.stops_data]
          SelectableRecycleGridLayout:
              cols: 1
              default_size: None, dp(26)
              default_size_hint: 1, None
              size_hint_y: None
              height: self.minimum_height
  </code></pre>
  
  <p>A sample of search_trip.py:</p>
  
  <pre><code>from kivy.app import App
  from kivy.lang import Builder
  from kivy.properties import ObjectProperty, ListProperty, BooleanProperty
  from kivy.uix.behaviors import FocusBehavior
  from kivy.uix.boxlayout import BoxLayout
  from kivy.uix.label import Label
  from kivy.uix.recyclegridlayout import RecycleGridLayout
  from kivy.uix.recycleview.layout import LayoutSelectionBehavior
  from kivy.uix.recycleview.views import RecycleDataViewBehavior
  from kivy.uix.screenmanager import (
      ScreenManager,
      Screen,
      NoTransition,
  )
  
  from search_stops.search import match_stop
  
  Builder.load_file("search_trip.kv")
  
  class TransportSearchApp(App):
      def build(self):
          screen_manager = ScreenManager(transition=NoTransition())
          screen_manager.add_widget(TripSearchScreen(name="search_trip_screen"))
          return screen_manager
  
  
  class TripSearchScreen(Screen):
      pass
  
  
  class MatchedStops(BoxLayout):
      stops_data = ListProperty([])
      departure_stop_name = ObjectProperty()
  
      def find_stop(self, stop: str) -&gt; None:
          matched_stops = match_stop(stop)
          self.stops_data = matched_stops
  
      def fill_departure_stop_name(self, dept_stop_name):
          self.ids.departure_stop.text = dept_stop_name
  
  
  class SelectableRecycleGridLayout(FocusBehavior, LayoutSelectionBehavior, RecycleGridLayout):
      """ Adds selection and focus behaviour to the view. """
  
  
  class SelectableLabel(RecycleDataViewBehavior, Label):
      """Add selection support to the Label"""
  
      index = None
      selected = BooleanProperty(False)
      selectable = BooleanProperty(True)
  
      def refresh_view_attrs(self, rv, index, data):
          """Catch and handle the view changes"""
          self.index = index
          return super(SelectableLabel, self).refresh_view_attrs(
              rv, index, data)
  
      def on_touch_down(self, touch):
          """Add selection on touch down"""
          if super(SelectableLabel, self).on_touch_down(touch):
              return True
          if self.collide_point(*touch.pos) and self.selectable:
              return self.parent.select_with_touch(self.index, touch)
  
      def apply_selection(self, rv, index, is_selected):
          """Respond to the selection of items in the view."""
          self.selected = is_selected
          if is_selected and rv.data[index]["text"] != "None":
              matched_stops = MatchedStops()
              matched_stops.departure_stop_name = rv.data[index]["text"]
              matched_stops.fill_departure_stop_name(rv.data[index]["text"])
  
  if __name__ == "__main__":
      TransportSearchApp().run()
  </code></pre>
  
  <p>I believe I may need to edit the text input directly on the <code>DepartureStopName</code> class, i.e. do something like:</p>
  
  <pre><code>class DepartureStopName(TextInput):
      text = StringProperty()
  
      def update_stop_name(self, txt):
          self.text = txt
  </code></pre>
  
  <p>But I didn't manage to get that going either - in that case, the text input field was always empty and the RecycleView wasn't shown at all.</p>