日期:2014-05-16 浏览次数:20460 次
<!-- 使用该文件来定义数据库和数据表,这里定义了数据库名字为notes_db,两个数据表 notes和categories --> <DATABASE version="1" name="notes_db"> <TABLE class=ke-zeroborder name="notes" to-string="%title%"> <FIELD name="title" size="128" type="text" obligatory="true"> <FIELD name="body" type="text" obligatory="true"> <FIELD name="category_id" type="foreign-key" foreign-table="categories"></FIELD> </FIELD> </FIELD> </TABLE> <TABLE class=ke-zeroborder name="categories" to-string="%name%description%" backup="no"> <FIELD name="name" size="128" type="string-identifier" obligatory="true"> <FIELD name="description" size="128" type="text" obligatory="true"></FIELD> </FIELD> </TABLE> </DATABASE>
<VALUES> <!-- table 指定数据所属的表格, id定义该数据的id值 --> <ROW id=1 table="categories"> <!-- 由于在tables.xml文件中定义的name field的类型为string-identifier,说明其初始化值取之于strings.xml中的定义 所以这里的name值对应为strings.xml中work的字符串值. --> <FIELD name="name" value="work"> <!-- description的类型为text,为这里定义的字符串 --> <FIELD name="description" value=" for work"> </FIELD> <ROW id=2 table="categories"> <FIELD name="name" value="friends"> <FIELD name="description" value=" for friends"> </FIELD> </FIELD> </ROW> </FIELD> </ROW> </VALUES>
package org.goodev; import android.app.ListActivity; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ListView; import android.widget.SimpleCursorAdapter; import com.android.dataframework.DataFramework; public class PruebaDataFramework extends ListActivity { private static final int ACTIVITY_CREATE=0; private static final int ACTIVITY_EDIT=1; private static final int INSERT_ID = Menu.FIRST; private static final int DELETE_ID = Menu.FIRST + 1; private static final int BACKUP_ID = Menu.FIRST + 2; private static final int RESTORE_ID = Menu.FIRST + 3; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notes_list); try { //初始化数据