您好,登錄后才能下訂單哦!
14.03.04
數據庫適配器
游標適配器cursorAdapter
Newview:創建行布局對象
Bindview:更新數據
Id默認必須為_id
private void show() { Cursor cursor = mDb.query("students", null, null, null, null, null, null); String[] from=new String[]{"name","phone"}; int[] to=new int[]{R.id.textView1,R.id.textView2}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item_list, cursor, from, to); listview.setAdapter(adapter); }
若任然報錯,將數據庫表刪除
適配器聲明為成員變量,則添加數據后無顯示
添加顯示:
重新遍歷游標
private void show() { Cursor cursor = mDb.query("students", null, null, null, null, null, null); String[] from=new String[]{"name","phone"}; int[] to=new int[]{R.id.textView1,R.id.textView2}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item_list, cursor, from, to); listview.setAdapter(adapter); }
simpleCursorAdapter:簡單游標適配器
顯示
優:代碼結構簡單
缺:支持的控件有限
textview、p_w_picpathview、radiobutton、checkbox(CompoundButton)
private void show() { Cursor cursor = mDb.query("students", null, null, null, null, null, null); String[] from=new String[]{"name","phone"}; int[] to=new int[]{R.id.textView1,R.id.textView2}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item_list, cursor, from, to); listview.setAdapter(adapter); }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。