According to your code,you have one table name Departments in sqlite database, you want to get data from this table, and populating these data into tableitems and display into ListView, am I right?
If yes, there are two steps you need to do, first you need to get data from sqlite database , second you need to create custom row in ListView to display tableitems.
private SQLiteConnection db;
private List<TableItem> items;
private void Btnget_Click(object sender, System.EventArgs e)
{
string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "Persons.db3");
db = new SQLiteConnection(dpPath);
foreach(var de in db.Table<Departments>())
{
TableItem item = new TableItem();
item.Heading = de.id.ToString();
item.SubHeading = de.FullName;
items.Add(item);
}
listview1.Adapter = new ListViewAdapter(this,items);
}
The Custom row in ListView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"/>
</LinearLayout>
The ListViewAdapter.cs:
public class ListViewAdapter : BaseAdapter<TableItem>
{
List<TableItem> items;
Activity context;
public ListViewAdapter(Activity context, List<TableItem> items) :base()
{
this.context = context;
this.items = items;
}
public override TableItem this[int position]
{
get { return items[position]; }
}
public override int Count
{
get { return items.Count; }
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = items[position];
View view = convertView;
if (view == null) // no view to re-use, create new
view = context.LayoutInflater.Inflate(Resource.Layout.CustomRow, null);
view.FindViewById<TextView>(Resource.Id.textView1).Text = item.Heading;
view.FindViewById<TextView>(Resource.Id.textView2).Text = item.SubHeading;
return view;
}
}