【发布时间】:2011-12-11 15:59:36
【问题描述】:
我又问了一个关于 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(); -
最后是 List Activity 的 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>
非常感谢您抽出宝贵时间查看并帮助我。我真的很难过,不知道从哪里开始......
【问题讨论】:
标签: android database sqlite list listview