【发布时间】:2017-11-04 15:14:00
【问题描述】:
我试图将我的 SQLite 表中的数据放入 List<string>,然后放入 ArrayAdapter<string> 和 ListView。
如何使用ArrayAdapter 将以下代码中的数据提取到ListView 中?
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,当您的数据基于Cursor时使用SimpleCursorAdapter -
我将如何添加
SimpleCursorAdapter? -
致电
ListView#setAdapter -
是的,但是声明
SimpleCursorAdapter?的代码行是什么 -
参见更新 1
标签: c# android sqlite listview android-arrayadapter