我是Android新手。我正在使用來自sqlite數據庫的數據創建列表視圖時遇到問題。 我發現下面這段代碼來創建聯繫人數據的列表視圖來自數據庫的Android Listview
public class Test extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get a cursor with all people
Cursor c = getContentResolver().query(Contacts.CONTENT_URI,CONTACT_PROJECTION, null, null, null);
startManagingCursor(c);
ListAdapter adapter = new SimpleCursorAdapter(this,
// Use a template that displays a text view
android.R.layout.simple_list_item_1,
// Give the cursor to the list adatper
c,
// Map the NAME column in the people database to...
new String[] {Contacts.DISPLAY_NAME},
// The "text1" view defined in the XML template
new int[] {android.R.id.text1});
setListAdapter(adapter);
}
private static final String[] CONTACT_PROJECTION = new String[] {
Contacts._ID,
Contacts.DISPLAY_NAME
};
}
現在我用這個代碼從數據庫
SQLiteDatabase myDB= null;
String TableName = "myTable";
myDB = this.openOrCreateDatabase("DatabaseName", MODE_PRIVATE, null);
// Get a cursor with all people
Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);
現在拉的數據我怎麼能結合這兩種代碼,以便我可以顯示數據從此列表中的數據庫中拉出。
在此先感謝。
我只需要使用DB數據代碼。那麼代碼是什麼? – 2012-01-04 00:10:00
如果是這樣的情況下,只需複製數據庫的代碼在你的問題並更換光標C = getcontentaresolver(......) – kosa 2012-01-04 00:13:47
我問這個嘗試過question.But其示值誤差 這裏檢查日誌文件 HTTP: //polbd.com/log.txt – 2012-01-04 00:34:34