Android 中SQLite技术实例详解
程序员文章站
2023-11-21 17:50:34
android和ios的数据库都是用sqlite来实现.
一,sqlite数据库简介:
轻量级:sqlite数据库是一个轻量级的数据库,适用于少量数据的curd;
文...
android和ios的数据库都是用sqlite来实现.
一,sqlite数据库简介:
轻量级:sqlite数据库是一个轻量级的数据库,适用于少量数据的curd;
文件本质:sqlite数据库支持大部分sql语法,允许使用sql语句操作数据库,其本质是一个文件,不需要安装启动。
数据读写:sqlite数据库打开只是一个文件的读写流。
二.简单的数据库语句知识
在android平台上,集成了一个嵌入式关系型数据库—sqlite,sqlite3支持null,integer,real(浮点数字),text(字符串文本)和blob(二进制对象)数据类型,实际上sqlite3也接受varchar(n),char(n),decimal(p,s)等数据类型,只不过在运算或保存时会转成对应的五种数据类型.
sqlite最大的特点是你可以把各种类型的数据保存到任何字段中,而不用关心字段声明的数据类型是什么。
今天我就用一个简单的列子来说明来实现sqlite。
实例代码:
import java.util.arraylist; import java.util.iterator; import com.hucc.huccgps.r; import android.app.activity; import android.app.dialog; import android.content.context; import android.content.intent; import android.content.sharedpreferences; import android.net.uri; import android.os.bundle; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.view.onclicklistener; import android.view.viewgroup; import android.view.window; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.baseadapter; import android.widget.button; import android.widget.edittext; import android.widget.imageview; import android.widget.listview; import android.widget.textview; import android.widget.toast; public class mainactivity extends activity { private static final string tag = "jgps/mainactivity"; private textview madd_white = null; private listview mwhitelistview = null; private context mcontext = null; private int mposition; private dbhelper mdbhelper = null; private whitelistadapter madapter = null; private arraylist<item> mwhitelistitem = new arraylist<item>(); @override protected void oncreate(bundle savedinstancestate) { log.d("jgps/start", "oncreate"); super.oncreate(savedinstancestate); setcontentview(r.layout.relative_main); this.mdbhelper = new dbhelper(this); this.mcontext = this; this.mwhitelistitem = new arraylist<item>(); this.mwhitelistview = (listview)findviewbyid(r.id.list_view); initdata(); this.mwhitelistview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> paramadapterview, view paramview, int paramint, long paramlong) { log.d("jgps/mainactivity", ""+paramint); mainactivity.this.updatewhitelist((item)mainactivity.this.mwhitelistitem.get(paramint)); } }); if (this.madd_white == null) return; madd_white.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { mainactivity.this.addcontactlist(); } }); log.d("jgps/end", "oncreate"); } private void initdata() { this.mwhitelistitem = this.mdbhelper.getrelativeslist(); if (this.mwhitelistitem.size() != 3) { for (int i = 1; i < 4; i++) { log.d("jgps/mainactivity", "initdata,id=" + i); item localitem1 = new item(); localitem1.setname(""); localitem1.setnumber(""); additemtolist(localitem1); updatesetting(i,""); } this.mwhitelistitem = this.mdbhelper.getrelativeslist(); } iterator localiterator = this.mwhitelistitem.iterator(); while (localiterator.hasnext()) { item localitem2 = (item) localiterator.next(); log.d("jgps/mainactivity", "initdata,id=" + localitem2.getid() + ",name = " + localitem2.getname() + ",number=" + localitem2.getnumber()); } this.madapter = new whitelistadapter(this, this.mwhitelistitem); this.mwhitelistview.setadapter(madapter); } private void updatesetting(int id, string phonenum) { switch (id) { case 1: putsting("phone_num1",phonenum); break; case 2: putsting("phone_num2",phonenum); break; case 3: putsting("phone_num3",phonenum); break; default: log.d("jgps/mainactivity", "wrong relative number id"); } } private void putsting(string paramstring1, string paramstring2) { sharedpreferences.editor localeditor = getsharedpreferences("sos_config", 0).edit(); localeditor.putstring(paramstring1, paramstring2); localeditor.apply(); } protected void updatewhitelist(item paramitem) { final item item = paramitem; log.d("jgps/mainactivity", "updatewhitelist------" + item.getid()); final dialog localdialog = new dialog(this, r.style.dialog); localdialog.show(); window localwindow = localdialog.getwindow(); localwindow.setcontentview(r.layout.dialog_editor); button localbutton1 = (button) localwindow.findviewbyid(r.id.btn_ok); button localbutton2 = (button) localwindow.findviewbyid(r.id.btn_cancel); final edittext phone = (edittext)localwindow.findviewbyid(r.id.phone); final edittext name = (edittext)localwindow.findviewbyid(r.id.name); name.settext(item.getname()); phone.settext(item.getnumber()); ((textview)localwindow.findviewbyid(r.id.title)).settext(r.string.edit_white); localbutton1.setonclicklistener(new onclicklistener() { @override public void onclick(view paramview) { if (phone.gettext().tostring().trim().length() == 0) { toast.maketext(mcontext, r.string.toast_tel, 2000).show(); return; } if (name.gettext().tostring().trim().length() == 0) { toast.maketext(mcontext, r.string.name_null, 2000).show(); return; } mainactivity.this.updatecontactindb(item.getid(), name.gettext().tostring(), phone.gettext().tostring()); int id = integer.parseint(item.getid()); updatesetting(id, phone.gettext().tostring()); toast.maketext(mcontext, r.string.edit_success, 2000).show(); localdialog.cancel(); } }); localbutton2.setonclicklistener(new onclicklistener() { @override public void onclick(view paramview) { localdialog.cancel(); } }); } protected void updatecontactindb(string paramstring1, string paramstring2, string paramstring3) { item localitem = new item(); localitem.setid(paramstring1); localitem.setname(paramstring2); localitem.setnumber(paramstring3); updateitemlist(localitem); } private void updateitemlist(item paramitem) { item localitem2; iterator localiterator1 = this.mwhitelistitem.iterator(); while (localiterator1.hasnext()) { localitem2 = (item) localiterator1.next(); if (localitem2.getid().equals(paramitem.getid())) { localitem2.setname(paramitem.getname()); localitem2.setnumber(paramitem.getnumber()); this.mdbhelper.updaterelativesitem(paramitem); } } log.d("jgps/mainactivity", "updateiteminlist ---------"); this.madapter = new whitelistadapter(this, this.mwhitelistitem); this.mwhitelistview.setadapter(madapter); } private void addcontactlist() { final dialog dialog = new dialog(this, r.style.dialog); dialog.show(); window window = dialog.getwindow(); window.setcontentview(r.layout.dialog_editor); button btn1 = (button)window.findviewbyid(r.id.btn_ok); button btn2 = (button)window.findviewbyid(r.id.btn_cancel); final edittext phone = (edittext)window.findviewbyid(r.id.phone); final edittext name = (edittext)window.findviewbyid(r.id.name); btn1.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { if (phone.gettext().tostring().trim().length() == 0) { toast.maketext(mcontext, r.string.toast_tel, 2000).show(); return; } if (name.gettext().tostring().trim().length() == 0) { toast.maketext(mcontext, r.string.name_null, 2000).show(); return; } if (mainactivity.this.mwhitelistitem.size()>3) { string str = mainactivity.this.getresources().getstring(r.string.full1)+ " " + 3 + " " + mainactivity.this.getresources().getstring(r.string.full2); toast.maketext(mcontext, str, 2000).show(); dialog.cancel(); return; } mainactivity.this.addcontacttodb(name.gettext().tostring(),phone.gettext().tostring()); dialog.cancel(); } }); btn2.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { dialog.cancel(); } }); } protected void deletecontactfromdb(string paramstring) { updatecontactindb(paramstring, "", ""); log.d("jgps/mainactivity", "===additemtolist = "+paramstring); int id = integer.parseint(paramstring); updatesetting(id, paramstring); toast.maketext(this.mcontext, r.string.delete_success, 2000).show(); } @override protected void onstart() { log.d("jgps/mainactivity", "onstart()"); super.onstart(); } protected void startcontactintent(int paramint) { log.d("jgps/mainactivity", "onclick " + paramint); this.mposition = paramint; intent localintent = new intent("android.intent.action.pick"); localintent.settype("vnd.android.cursor.dir/phone_v2"); startactivityforresult(localintent, 100); } protected void addcontacttodb(string paramstring1, string paramstring2) { iterator localiterator = this.mwhitelistitem.iterator(); while (localiterator.hasnext()) { if(((item)localiterator.next()).getnumber().equals(paramstring2)){ toast.maketext(mcontext, r.string.replace, 2000).show(); return; } } item localitem = new item(); localitem.setname(paramstring1); localitem.setnumber(paramstring2); additemtolist(localitem); toast.maketext(mcontext, r.string.replace, 2000).show(); } private void additemtolist(item localitem) { log.d("jgps/mainactivity", "additemtolist,name = " + localitem.getname() + ",number=" + localitem.getnumber()); this.mdbhelper.addrelativesitem(localitem); this.mwhitelistitem = this.mdbhelper.getrelativeslist(); this.madapter = new whitelistadapter(this, this.mwhitelistitem); this.mwhitelistview.setadapter(madapter); } public void startactivityforresult(intent paramintent, int paramint) { super.startactivityforresult(paramintent, paramint); } private class whitelistadapter extends baseadapter{ private context context; private layoutinflater minflater; private arraylist<item> listitem; public whitelistadapter(context context1, arraylist<item> whitelistitem) { this.context = context1; this.listitem = whitelistitem; this.minflater = layoutinflater.from(context); } public int getcount() { if ((this.listitem !=null) && (this.listitem.size() > 0)) { return 3; } return 0; } public object getitem(int paramint) { if ((this.listitem != null) && (this.listitem.size() > 0)) return this.listitem.get(paramint); return null; } public long getitemid(int paramint) { return 0l; } @override public view getview(int paramint, view paramview, viewgroup paramviewgroup) { log.d("jgps/mainactivity", "getview,position=" + paramint + ",name=" + ((item)this.listitem.get(paramint)).getname() + ",num=" + ((item)this.listitem.get(paramint)).getnumber()); if (paramview == null) { final viewholder localviewholder = new viewholder(); paramview = this.minflater.inflate(r.layout.relative_list_item, null); localviewholder.ivcall = (imageview)paramview.findviewbyid(r.id.imageview_call); localviewholder.ivdelete = (imageview)paramview.findviewbyid(r.id.imageview_delete); localviewholder.ivselect = (imageview)paramview.findviewbyid(r.id.recipients_picker); localviewholder.txtview_name = (textview)paramview.findviewbyid(r.id.txtview_name); localviewholder.txtview_tel = (textview)paramview.findviewbyid(r.id.txtview_number); paramview.settag(localviewholder); localviewholder.position = paramint; localviewholder.ivselect.settag(localviewholder); if ((this.listitem.get(paramint)== null)|| (((item)this.listitem.get(paramint)).getnumber() == null) || (((item)this.listitem.get(paramint)).getnumber().equals(""))) { localviewholder.ivcall.setvisibility(view.gone); localviewholder.ivselect.setvisibility(view.visible); string str1 = mainactivity.this.getstring(r.string.family_string); string str2 = str1 + (paramint + 1) + ":"; localviewholder.txtview_name.settext(str2); localviewholder.txtview_tel.settext(r.string.click_to_add); }else { localviewholder.ivcall.setvisibility(view.visible); localviewholder.ivselect.setvisibility(view.gone); localviewholder.txtview_name.settext(((item)this.listitem.get(paramint)).getname()); localviewholder.txtview_tel.settext(((item)this.listitem.get(paramint)).getnumber()); } localviewholder.ivselect.setonclicklistener(new onclicklistener() { @override public void onclick(view paramview) { mainactivity.whitelistadapter.viewholder localviewholder = (mainactivity.whitelistadapter.viewholder)paramview.gettag(); log.d("jgps/mainactivity", "getview,mposition=" + mainactivity.this.mposition); mainactivity.this.startcontactintent(localviewholder.position); } }); if ((!(((item)this.listitem.get(paramint)).getname().equals(""))) || (!(((item)this.listitem.get(paramint)).getnumber().equals("")))) { localviewholder.ivdelete.setvisibility(view.visible); }else { localviewholder.ivdelete.setvisibility(view.gone); } localviewholder.ivcall.setonclicklistener(new onclicklistener() { @override public void onclick(view paramview) { intent localintent = new intent("android.intent.action.call", uri.parse("tel:" + ((item)mainactivity.whitelistadapter.this.listitem.get(localviewholder.position)).getnumber())); mainactivity.whitelistadapter.this.context.startactivity(localintent); } }); localviewholder.ivdelete.setonclicklistener(new onclicklistener() { @override public void onclick(view paramview) { if(paramview.getid() != r.id.imageview_delete) return; final string str = ((item)mainactivity.whitelistadapter.this.listitem.get(localviewholder.position)).getid(); log.d("jgps/mainactivity", "delete item onclick,strid=" + str + ",position=" + localviewholder.position); final dialog localdialog = new dialog(mainactivity.whitelistadapter.this.context, r.style.dialog); localdialog.show(); window localwindow = localdialog.getwindow(); localwindow.setcontentview(r.layout.dialog_delete); ((textview)localwindow.findviewbyid(r.id.txtview_delete)).settext(mainactivity.whitelistadapter.this.context.getresources().getstring(r.string.delete_one) + "'" + ((item)mainactivity.whitelistadapter.this.listitem.get(localviewholder.position)).getname() + "'" + mainactivity.whitelistadapter.this.context.getresources().getstring(r.string.delete_two)); button localbutton1 = (button) localwindow.findviewbyid(r.id.btn_ok); button localbutton2 = (button) localwindow.findviewbyid(r.id.btn_cancel); localbutton1.setonclicklistener(new onclicklistener() { @override public void onclick(view paramview) { mainactivity.this.deletecontactfromdb(str); localdialog.cancel(); } }); localbutton2.setonclicklistener(new onclicklistener() { @override public void onclick(view paramview) { localdialog.cancel(); } }); } }); }else { } return paramview; } public class viewholder{ public imageview ivcall; public imageview ivdelete; public imageview ivselect; public int position; public textview txtview_name; public textview txtview_tel; } } } import java.util.arraylist; import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.util.log; public class dbhelper extends sqliteopenhelper { public static final string table_relatives_content = "relativescontent"; public static final int version = 1; //版本 public static final string dbname = "sosdb"; //数据库的名字 public static context mcontext = null; public sqlitedatabase db = null; public dbhelper(context paramcontext) { super(paramcontext, "sosdb", null, 1); mcontext = paramcontext; } // 创建数据库表 @override public void oncreate(sqlitedatabase paramsqlitedatabase) { paramsqlitedatabase.execsql("create table relativescontent(id integer primary key autoincrement,name text , number text)"); closedatabase(); } private void closedatabase() { if (this.db == null) return; this.db.close(); } @override public void onupgrade(sqlitedatabase paramsqlitedatabase, int paramint1, int paramint2) { oncreate(paramsqlitedatabase); } //查询方法 public arraylist<item> getrelativeslist() { string idf = null; string namef = null; string numf = null; arraylist localarraylist = new arraylist(); opendatabase(); cursor localcursor = this.db.query("relativescontent", null, null, null, null, null, null); if(localcursor == null) return localarraylist; while (localcursor.movetonext()) { item localitem = new item(); idf = localcursor.getstring(localcursor.getcolumnindex("id")); namef = localcursor.getstring(localcursor.getcolumnindex("name")); numf = localcursor.getstring(localcursor.getcolumnindex("number")); localitem.setid(idf); log.d("jgps/mainactivity", "dbid=" + idf); if ((namef == null) || ("".equals(namef))) { localitem.setname(""); }else { localitem.setname(namef); } if ((numf == null) || ("".equals(numf))) { localitem.setnumber(""); }else { localitem.setnumber(numf); } localarraylist.add(localitem); } return localarraylist; } //写入数据 private void opendatabase() { this.db = super.getwritabledatabase(); } //添加数据 public boolean addrelativesitem(item localitem) { opendatabase(); contentvalues localcontentvalues = new contentvalues(); localcontentvalues.put("name", localitem.getname()); localcontentvalues.put("number", localitem.getnumber()); long l = this.db.insert("relativescontent", null, localcontentvalues); closedatabase(); return (1<=0l); } //更新数据 public boolean updaterelativesitem(item paramitem) { opendatabase(); contentvalues localcontentvalues = new contentvalues(); localcontentvalues.put("name", paramitem.getname()); localcontentvalues.put("number", paramitem.getnumber()); sqlitedatabase localsqlitedatabase = this.db; string[] arrayofstring = new string[1]; arrayofstring[0] = paramitem.getid(); long l = localsqlitedatabase.update("relativescontent", localcontentvalues, "id=?", arrayofstring); closedatabase(); return (1 <= 0l); } } import java.io.serializable; public class item implements serializable{ private string _id; private string name; private string number; public item() { // todo auto-generated constructor stub } public void item(string paramstring1, string paramstring2, string paramstring3) { this._id = paramstring1; this.name = paramstring2; this.number = paramstring3; } public string getid() { return _id; } public void setid(string paramstring) { this._id = paramstring; } public string getname() { return name; } public void setname(string paramstring) { this.name = paramstring; } public string getnumber() { return number; } public void setnumber(string paramstring) { this.number = paramstring; } }
这是基本的数据程序。
xml
relative_main
<linearlayout android:orientation="vertical" android:background="@color/background_color" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <relativelayout android:background="@drawable/title_bar" android:layout_width="fill_parent" android:layout_height="50.0sp"> <textview android:textsize="@dimen/title_size" android:textstyle="bold" android:textcolor="@color/title_color" android:gravity="center" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="50.0sp" android:text="@string/relative_name" android:layout_centerinparent="true" /> </relativelayout> <relativelayout android:id="@+id/white_content" android:layout_width="fill_parent" android:layout_height="wrap_content"> <listview android:id="@+id/list_view" android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollingcache="true" android:cachecolorhint="#00000000" android:divider="@null" android:fastscrollenabled="false" /> </relativelayout> </linearlayout> dialog_editor <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center" android:orientation="vertical" android:id="@+id/linearlayout_dialog" android:layout_width="300.0dip" android:layout_height="wrap_content"> <textview android:textsize="20.0sp" android:textcolor="#ffffffff" android:gravity="center" android:id="@+id/title" android:background="@drawable/popup_topbg" android:layout_width="fill_parent" android:layout_height="60.0dip" android:text="@string/add_white" /> <linearlayout android:orientation="vertical" android:background="@drawable/simple_dialog_list_item_bg" android:paddingleft="5.0dip" android:paddingtop="5.0dip" android:paddingright="5.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content"> <linearlayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="8.0dip" android:layout_margintop="6.0dip" android:layout_marginright="6.0dip" android:layout_marginbottom="2.0dip"> <textview android:textsize="16.0sp" android:textcolor="#ff000000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/name" /> <edittext android:gravity="left|center" android:id="@+id/name" android:background="@drawable/text_input" android:layout_width="210.0dip" android:layout_height="wrap_content" android:layout_marginleft="8.0dip" android:hint="@string/name_hint" android:singleline="true" /> </linearlayout> <linearlayout android:layout_gravity="center" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginleft="8.0dip" android:layout_marginright="6.0dip"> <textview android:textsize="16.0sp" android:textcolor="#ff000000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/address" /> <edittext android:gravity="left|center" android:id="@+id/phone" android:background="@drawable/text_input" android:layout_width="210.0dip" android:layout_height="wrap_content" android:layout_marginleft="8.0dip" android:hint="@string/address_hint" android:singleline="true" android:inputtype="phone" /> </linearlayout> <include layout="@layout/divider" /> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="54.0dip"> <button android:textsize="20.0sp" android:id="@+id/btn_ok" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/ok" android:layout_weight="5.0" style="@style/dialog_item" /> <view android:background="#ffbcc2c5" android:layout_width="2.0px" android:layout_height="fill_parent" /> <button android:textsize="20.0sp" android:id="@+id/btn_cancel" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/cancel" android:layout_weight="5.0" style="@style/dialog_item" /> </linearlayout> </linearlayout> </linearlayout>
relative_list_item
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center_vertical" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="40.0dip" style="@style/list_item_background"> <linearlayout android:gravity="center_vertical" android:orientation="horizontal" android:id="@+id/ll_line1" android:paddingleft="5.0dip" android:paddingright="5.0dip" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="1.0"> <textview android:textsize="@dimen/list_font_size_0" android:textstyle="bold" android:textcolor="@color/list_item_text" android:ellipsize="end" android:gravity="center" android:id="@+id/txtview_name" android:paddingbottom="3.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxwidth="80.0dip" android:singleline="true" /> <textview android:textsize="@dimen/list_font_size_1" android:textstyle="bold" android:textcolor="@color/list_item_text" android:ellipsize="end" android:gravity="center" android:id="@+id/txtview_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10.0dip" android:singleline="true" /> </linearlayout> <imageview android:layout_gravity="center_vertical" android:id="@+id/imageview_call" android:background="@drawable/btn_dial_action" android:paddingleft="8.0dip" android:paddingtop="8.0dip" android:paddingright="8.0dip" android:paddingbottom="8.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/call_phone" />" <imageview android:layout_gravity="center_vertical" android:id="@+id/recipients_picker" android:background="@drawable/add_contact_selector" android:layout_width="65.0dip" android:layout_height="65.0dip" android:layout_marginleft="2.0dip" android:layout_marginright="2.0dip" android:scaletype="fitxy" /> <view android:id="@+id/imageview_divider" android:background="#2b2b2b2b" android:layout_width="2.0dip" android:layout_height="40.0dip" /> <imageview android:layout_gravity="right|center" android:id="@+id/imageview_delete" android:paddingleft="8.0dip" android:paddingtop="8.0dip" android:paddingright="8.0dip" android:paddingbottom="8.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/del_cross" /> </linearlayout>
dialog_delete
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center" android:orientation="vertical" android:id="@+id/linearlayout_dialog" android:layout_width="300.0dip" android:layout_height="wrap_content"> <textview android:textsize="20.0sp" android:textcolor="#ffffffff" android:gravity="center" android:background="@drawable/popup_topbg" android:layout_width="fill_parent" android:layout_height="60.0dip" android:text="@string/tips" /> <linearlayout android:orientation="vertical" android:background="@drawable/simple_dialog_list_item_bg" android:paddingleft="5.0dip" android:paddingtop="12.0dip" android:paddingright="5.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content"> <textview android:textsize="20.0sp" android:textcolor="#ff000000" android:id="@+id/txtview_delete" android:paddingbottom="12.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="8.0dip" android:layout_marginright="6.0dip" /> <include layout="@layout/divider" /> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="54.0dip"> <button android:textsize="20.0sp" android:id="@+id/btn_ok" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/dialog_yes" android:layout_weight="5.0" style="@style/dialog_item" /> <view android:background="#ffbcc2c5" android:layout_width="2.0px" android:layout_height="fill_parent" /> <button android:textsize="20.0sp" android:id="@+id/btn_cancel" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/dialog_no" android:layout_weight="5.0" style="@style/dialog_item" /> </linearlayout> </linearlayout> </linearlayout>
这是一个简单的demo,我这里就不详细说明数据库的细节了,对于已经很熟悉数据库的,可以查看android官网有说明的,
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!