title: How to retrieve data from sqlite Db and set to kivy TextInput fields?
body: <p>I'm learning kivy by making small applications from kivy docs and other online resources. The current code has 
  two textinput fields (UserID, UserName) to store values in the db, using RecycleView the stored data is displayed
  on buttons with the Kivy GUI. </p>
  
  <p>On button press, I require corresponding data from the db to be set to the respective textinput fields. i.e. On 
  pressing button with UserID 1 , textinput field should display values of UserID and UserNames from that row.</p>
  
  <p><strong>main.py</strong> </p>
  
  <pre><code>import sqlite3
  from kivy.app import App
  from kivy.uix.boxlayout import BoxLayout
  from kivy.uix.recycleview.views import RecycleDataViewBehavior
  from kivy.uix.button import Button
  from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty
  from kivy.uix.recyclegridlayout import RecycleGridLayout
  from kivy.uix.behaviors import FocusBehavior
  from kivy.uix.recycleview.layout import LayoutSelectionBehavior
  
  class SelectableRecycleGridLayout(FocusBehavior, LayoutSelectionBehavior,
                                    RecycleGridLayout):
      ''' Adds selection and focus behaviour to the view. '''
  
  
  class SelectableButton(RecycleDataViewBehavior, Button):
      ''' Add selection support to the Button '''
      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(SelectableButton, self).refresh_view_attrs(rv, index, data)
  
      def on_touch_down(self, touch):
          ''' Add selection on touch down '''
          if super(SelectableButton, 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
  
  class RV(BoxLayout):
      ''' Creates Db conn, table, and saves data, retrives stored data and
      displays in the RecycleView .'''
      data_items = ListProperty([])
  
      def __init__(self, **kwargs):
          super(RV, self).__init__(**kwargs)
          self.create_table()
          self.get_users()
  
      def create_table(self):
          connection = sqlite3.connect("demo.db")
          cursor = connection.cursor()
          sql = """CREATE TABLE IF NOT EXISTS Users(
          UserID integer PRIMAY KEY,
          UserName text NOT NULL)"""
          cursor.execute(sql)
          connection.close()
  
      def get_users(self):
          connection = sqlite3.connect("demo.db")
          cursor = connection.cursor()
  
          cursor.execute("SELECT * FROM Users ORDER BY UserID ASC")
          rows = cursor.fetchall()
  
          # create data_items
          for row in rows:
              for col in row:
                  self.data_items.append(col)
  
      def save(self):
          connection = sqlite3.connect("demo.db")
          cursor = connection.cursor()
  
          UserID = self.ids.no.text
          UserName = self.ids.name.text
  
          try:
              save_sql="INSERT INTO Users (UserID, UserName) VALUES (?,?)"
              connection.execute(save_sql,(UserID, UserName))
              connection.commit()
              connection.close()
          except sqlite3.IntegrityError as e:
              print("Error: ",e)
  
  class TestApp(App):
      title = "Kivy RecycleView &amp; SQLite3 Demo"
  
      def build(self):
          return RV()
  
  
  if __name__ == "__main__":
      TestApp().run()
  </code></pre>
  
  <p><strong>test.kv</strong></p>
  
  <pre><code>#:kivy 1.10.0
  &lt;TextInputPopup&gt;:
      title: "Popup"
      size_hint: None, None
      size: 400, 400
      auto_dismiss: False
  
      BoxLayout:
          orientation: "vertical"
          TextInput:
              id: txtinput
              text: root.obj_text
          Button:
              size_hint: 1, 0.2
              text: "Save Changes"
              on_release:
                  root.obj.update_changes(txtinput.text)
                  root.dismiss()
          Button:
              size_hint: 1, 0.2
              text: "Cancel Changes"
              on_release: root.dismiss()
  
  
  &lt;SelectableButton&gt;:
      # Draw a background to indicate selection
      canvas.before:
          Color:
              rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
          Rectangle:
              pos: self.pos
              size: self.size
  
  &lt;RV&gt;:
      BoxLayout:
          orientation: "vertical"
          user_no_text_input: no
          user_name_text_input: name
  
          Label:
              text: "USER NUMBER"
              size_hint: (.5, None)
              height: 30
          TextInput:
              id: no
              size_hint: (.5, None)
              height: 30
              multiline: False
          Label:
              text: "USER NAME"
              size_hint: (.5, None)
              height: 30
          TextInput:
              id: name
              size_hint: (.5, None)
              height: 30
              multiline: False
          Button:
              id: save_btn
              text: "SAVE BUTTON"
              height: 50
              width: 100
              on_press: root.save()
  
          GridLayout:
              size_hint: 1, None
              size_hint_y: None
              height: 25
              cols: 2
  
              Label:
                  text: "User ID"
              Label:
                  text: "User Name"
  
          BoxLayout:
              RecycleView:
                  viewclass: 'SelectableButton'
                  data: [{'text': str(x)} for x in root.data_items]
                  SelectableRecycleGridLayout:
                      cols: 2
                      default_size: None, dp(26)
                      default_size_hint: 1, None
                      size_hint_y: None
                      height: self.minimum_height
                      orientation: 'vertical'
                      multiselect: True
                      touch_multiselect: True
  </code></pre>