我想从我的SQLite表中获取数据到List<string>
,然后到ArrayAdapter<string>
和ListView
。 如何使用ArrayAdapter
将下面的代码拉到ListView
?从SQLite中获取数据到ArrayAdapter/ListView - Android的C#Xamarin
DB Helper.cs:
public List<string> getNoteList()
{
List<string> noteList = new List<string>();
SQLiteDatabase db = this.ReadableDatabase;
ICursor cursor = db.Query(DB_TABLE, new string[] { DB_COLUMN}, null, null, null, null, null);
while (cursor.MoveToNext())
{
int index = cursor.GetColumnIndex(DB_COLUMN);
noteList.Add(cursor.GetString(index));
}
return noteList;
}
正如你可以看到它被放入noteList
,但我怎么会使得noteList
进入一个ListView
编写一个阵列适配器?
更新1: MainActivity.cs
public void LoadNoteList()
{
List<string> noteList = dbHelper.getNoteList();
adapter = new ArrayAdapter<string>(this, Resource.Layout.list_black_text, noteList);
lvNotes.Adapter = adapter;
}
错误:
'ArrayAdapter',使用'SimpleCursorAdapter',而不是当你的数据是基于Cursor'' – pskink
究竟如何,我会添加一个'SimpleCursorAdapter'不使用? – DEFALT
通过调用'ListView#setAdapter' – pskink