我想從我的數據庫填充一個列表。從SQLite填充CheckList
我有以下代碼:
setContentView(R.layout.pro);
addProFromDB();
}
我應該如何填充多xCodexInlinexPlacexHolderx?
private void addProFromDB() {
// TODO Auto-generated method stub
ArrayList<String> results = new ArrayList<String>();
SQLiteDatabase sampleDB = null;
try {
list = (ListView)findViewById(android.R.id.list);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
sampleDB = this.openOrCreateDatabase(SAMPLE_DB_NAME, 1, null);
sampleDB.execSQL("create table tbl_product("
+ "pro_id integer PRIMARY KEY autoincrement,"
+ "pro_name text," + "pro_price integer);");
sampleDB.execSQL("insert into tbl_product(pro_name, pro_price) values ('oil', '200');");
Cursor c = sampleDB.query(SAMPLE_TABLE_NAMES, null, null, null, null, null,
null);
char pro_nameColumnIndex = (char) c.getColumnIndexOrThrow("pro_name");
int pro_priceColumnIndex = (int) c.getColumnIndexOrThrow("pro_price");
} finally {
if (sampleDB != null)
sampleDB.close();
}
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, new ArrayList()));
它不給予任何錯誤,但沒有表現出任何插入的項目。
感謝您sugestions..i知道使用此代碼的AV不錯的辦法,但在我的情況它滿足requiremnt ..我有3個選項卡,並在每個選項卡上單擊其相關的表格創建..你能幫我我應該用什麼部分來填補這個空陣列...謝謝 – Numair
[從這裏開始快速解決方案](http://www.vogella.com/articles/AndroidSQLite/article.html#databasetutorial_database) –