SimpleCursorAdapter
可用于从 中获取数据database
并显示在 中ListView
。
这是实现您的要求的示例代码:
int[] names = new int[] {R.id.Full_Name,R.id.name};
private static final String fields[] = {"DatabaseColumn_Name1", "DatabaseColumn_Name2"};
ListView = (ListView)findViewById(R.id.list1);
DataBaseHelper myDbHelper = new DataBaseHelper(null);
myDbHelper = new DataBaseHelper(this);
String sql ="SELECT STATEMENT";
Cursor cdata = myDbHelper.getView(sql);
if (cdata != null)
{
cdata.moveToFirst();
while (cdata.isAfterLast() == false) {
String tx = (cdata.getString(2));
cdata.moveToNext();
}
startManagingCursor(cdata);
CursorAdapter adaptr = new MyCursorAdapter(
getApplicationContext(), R.layout.listview1, cdata, fields, names);