title: Initializing a ListAdapter in Kivy file
body: <p>I'm new to Kivy and really like the separation between the code and the UI spec in the Kivy file.  I was hitting a roadblock in understanding how I might define a ListAdapter inside the Kivy file.  For example, here is a ListAdapter that is fully defined in the Python code:</p>
  
  <pre><code>class TestPop(Popup):
  
      a = ['a', 'b', 'c', 'd', 'e', 'f','g']
  
      def __init__(self, **kwargs):
          super(TestPop, self).__init__(**kwargs)
          aAdapter = ListAdapter(data=self.a, cls=ListItemButton,
              args_converter = lambda row_index, x: {'text': x,'size_hint_y': None,
                  'height': 50})
          aAdapter.bind(on_selection_change=self.click)
          myBox = BoxLayout(orientation = 'vertical')
          myBox.add_widget(ListView(size_hint = (1,0.8), adapter = aAdapter))
          myBox.add_widget(Label(text = 'my pop', size_hint = (1,0.2)))
          self.add_widget(myBox)
          self.open
  
      def click(self, *args):
          print('click:{}'.format(args[0].selection[0].text))
  </code></pre>
  
  <p>Now, I can put part of the UI definition into the kivy file by changing the Python code to:</p>
  
  <pre><code>class TestPop2(Popup):
  
      a = ['a', 'b', 'c', 'd', 'e', 'f','g']
  
      def __init__(self, **kwargs):
          self.aAdapter = ListAdapter(data=self.a, cls=ListItemButton,
              args_converter = lambda row_index, x: {'text': x,'size_hint_y': None,
                  'height': 50})
          self.aAdapter.bind(on_selection_change=self.click)
          super(TestPop2, self).__init__(**kwargs)
          self.open
  
      def click(self, *args):
          print('click:{0}'.format(args[0].selection[0].text))
  </code></pre>
  
  <p>and create a Kivy file:</p>
  
  <pre><code>&lt;TestPop2&gt;:
      title: 'type2 popup'
      BoxLayout:
          orientation: 'vertical'
          ListView:
              size_hint: (1,0.8)
              adapter: root.aAdapter
          Label:
              text: 'Test2 pop'
              size_hint: (1,0.2)
  </code></pre>
  
  <p>This will work.  But, I have problems moving the ListAdapter into the kivy file.  I tried this code:</p>
  
  <pre><code>class TestPop3(Popup):
      '''uses kv file but can't get on_selection_change to work
      '''
      a = ListProperty(['a', 'b', 'c', 'd', 'e', 'f','g'])
  
      def __init__(self, **kwargs):
          super(TestPop3, self).__init__(**kwargs)
          self.open
  
      def click(self, *args):
          print('click:{0}'.format(args[0].selection[0].text))
  </code></pre>
  
  <p>with this kv file:</p>
  
  <pre><code>&lt;TestPop3&gt;:
      title: 'type3 popup'
      BoxLayout:
          orientation: 'vertical'
          ListView:
              size_hint: (1,0.8)
              adapter: ListAdapter(data=root.a,cls=ListItemButton,args_converter= lambda row_i, x:{'text':x,'size_hint_y':None,'height':50},on_selection_change= root.click)
          Label:
              text: 'Test3 pop'
              size_hint: (1,0.2)           
  </code></pre>
  
  <p>but the on_selection_change doesn't work.  I am assuming there is something critical in when or how I bind the function to the event, and was trying to pass a reference back to the Python code through an ObjectProperty, but I can't figure it out.</p>
  
  <p>Kivy ListAdapter documentation is located at <a href="http://kivy.org/docs/api-kivy.adapters.listadapter.html" rel="nofollow">http://kivy.org/docs/api-kivy.adapters.listadapter.html</a>, but I couldn't find the solution there.  Some excellent code examples are at <a href="http://kivy.org/docs/api-kivy.uix.listview.html" rel="nofollow">http://kivy.org/docs/api-kivy.uix.listview.html</a>, but I didn't see any that helped me with this question.</p>
  
  <p>I'm also new to Python, so if there are comments about making my code more Pythonic or more accurate terminology in describing this issue, I'm all ears.</p>