SimpleCursorAdapter
可以被用来获得从所述ListView
和database
显示的数据。
下面是实现您的要求的示例代码:
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);
试试这个 > ['http://stackoverflow.com/questions/9785563/how-to-write-reusable-code-for-database-in-android/9785657#9785657'][1] [1]:http://stackoverflow.com/questions/9785563/how-to-write-reusable-code-for-database-in-android/9785657#9785657 – Hasmukh