title: Xamarin Android C#: Populate ListView Custom Row With Data From SQLite Database
body: <p>I'm tring to create a ListView which is fed data from an SQLite Database (pre-existing db file). The ListView uses a custom row which is one of the aspects which baffle me; How do I extract the data and then assign it to a TextView in the custom row?</p>
  
  <p>I'm new to Xamarin, so would really appreciate any guidance you can give me on this, Thank you!</p>
  
  <p>Current Dialog Box Error When Run:</p>
  
  <pre><code>Java.Lang.ClassNotFoundException: Didn't find class      "md5c4f65b5cf99ab8e97737acf0f8ec7efd.DBHelper" on path: DexPathList[[zip file "/data/app/AppName.Droid-1/base.apk"],nativeLibraryDirectories=[/data/app/AppName.Droid-1/lib/arm, /system/fake-libs, /data/app/AppName.Droid-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
  </code></pre>
  
  <p>'MainActivity':</p>
  
  <pre><code>public class EateriesActivity : Activity
  {
      protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
  
          Title = "Find An Eatery";
          SetContentView(Resource.Layout.Eateries);
  
  
          DBHelper db = new DBHelper();
          db.CreateDatabase();
          db.CreateTable();
  
          var items = db.GetData();
          var listView = FindViewById&lt;ListView&gt;(Resource.Id.EateryList_ListView);
  
          listView.Adapter = new ArrayAdapter&lt;string&gt;(this, Resource.Layout.Eatery_ListView_Row, items);
      }
  }
  </code></pre>
  
  <p>ListViewAdapter (is this necessary?):</p>
  
  <pre><code>class ListViewAdapter : BaseAdapter&lt;Eatery&gt;
  {
      private List&lt;Eatery&gt; myItems;
      private Context myContext;
      public ListViewAdapter(Context context, List&lt;Eatery&gt; items)
      {
          myItems = items;
          myContext = context;
      }
      public override int Count
      {
          get { return myItems.Count; }
      }
  
      public override long GetItemId(int position)
      {
          return position;
      }
  
      public override Eatery this[int position]
      {
          get
          {
              return myItems[position];
          }
      }
  
      public override View GetView(int position, View convertView, ViewGroup parent)
      {
          View row = convertView;
  
          if (row == null)
          {
              row = LayoutInflater.From(myContext).Inflate(Resource.Layout.Eatery_ListView_Row, null, false);
          }
  
          TextView placeName = row.FindViewById&lt;TextView&gt;(Resource.Id.placeName);
          placeName.Text = myItems[position].Name;
  
          TextView placeTown = row.FindViewById&lt;TextView&gt;(Resource.Id.placeTown);
          placeTown.Text = myItems[position].Town;
  
          return row;
      }
  }
  </code></pre>
  
  <p>Eatery:</p>
  
  <pre><code>public class Eatery
  {
      [PrimaryKey]
      public string ID { get; set; }
      public string Image { get; set; }
      public string Name { get; set; }
      public string Description { get; set; }
      public string Address1 { get; set; }
      public string Town { get; set; }
      public string PostCode { get; set; }
      public string Cuisine { get; set; }
  }
  </code></pre>
  
  <p>DBHelper:</p>
  
  <pre><code>public class DBHelper
  {
      private static string DB_PATH = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
      private static string DB_NAME = "EateryDB.db";
  
      public void CreateDatabase()
      {
          string dbPath = Path.Combine(DB_PATH, DB_NAME);
          var db = new SQLiteConnection(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), dbPath);
      }
  
      public void CreateTable()
      {
          string dbPath = Path.Combine(DB_PATH, DB_NAME);
          var db = new SQLiteConnection(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), dbPath);
          db.CreateTable&lt;Eatery&gt;();
      }
  
      public List&lt;string&gt; GetData()
      {
          string dbPath = Path.Combine(DB_PATH, DB_NAME);
          var db = new SQLiteConnection(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), dbPath);
          List&lt;string&gt; data = new List&lt;string&gt;();
          foreach (var item in db.Table&lt;Eatery&gt;())
          {
              var place = item.Name.ToString(); item.Town.ToString();
  
              data.Add(place);
          }
          return data;
      }
  </code></pre>