我回来了关于Android数据库的另一个问题。如何显示Android数据库内容?
我正在存储一个简单的字符串到我的android数据库,然后希望显示所有的条目列表。但是,该列表在我的模拟器(或我的实际设备)上没有显示任何内容,LogCat也没有(将条目保存到数据库或调用它们时)。
下面你有我的代码
保存项功能:
public long createEntry(String entry){ ContentValues initialValues = new ContentValues(); initialValues.put(KEY_ENTRY, entry); return db.insert(DATABASE_TABLE, null, initialValues); }
的获取条目功能:
public Cursor fetchAllEntries(){ return db.query(DATABASE_TABLE,new String [] {KEY_ROW_ID, KEY_ENTRY}, null, null, null, null, null); }
列表活动:
entryList = (ListView)findViewById(R.id.recordsList); Cursor c = dbAdapter.fetchAllEntries(); if(c!=null){ startManagingCursor(c); String [] from = new String [] {PirelliDbAdapter.KEY_ENTRY}; int [] to = new int [] {R.id.text1}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.entryrow, c, from, to); entryList.setAdapter(adapter); } dbAdapter.close();
最后名单活动的XML:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/recordsList" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:id="@+id/textViewList" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
非常感谢您抽出时间来看看在这个和帮助我。我真的难住,不知道从哪里走...
这个链接是死 – Ixx