版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
PAGE1-安卓实训设计报告安卓通讯录设计题目:安卓通讯录班级:姓名:学号:指导老师:日期:
内容要求一、题目分析,功能要求。1.1实验目的熟悉Android软件开发的基本架构利用Eclipse和ADT插件设计通讯录1.2功能本手机通讯录工具主要实现五大功能:联系人的查询:字段查询,分组查询,字母排序查询;增加、删除联系人以及修改联系人信息;导入、导出联系人;发送联系人信息;设置。二、实验设计2.1UI设计我们用一个ListView来显示整个通讯录,其中用TextView显示每一记录,他们的xml文件分别为:main.xml(通讯录主界面),addres.xml(添加联系人界面),list_item.xml(浏览联系人界面),find.xml(查找联系人界面)。2.2数据库的设计Android中的android.database.sqlite.SQLiteOpenHelper类是一个专门用于数据库创建和版本管理的辅助类。因此,为了更好的管理数据库,这里我们创建一个继承自SQLiteOpenHelper的辅助类DBHelper来维护和更新数据库。2.3功能的设计为了在主界面中浏览联系人的信息,并且创建主要菜单栏,我们设计了MainActivity类,主要用于显示联系人信息和菜单栏,通过菜单栏,实现通讯录的相关功能。AddressBook类主要是为了实现联系人的添加功能,并且实现信息的保存后跳转到主界面。Findactivity类主要是为了实现联系人的查找功能,输入联系人的姓名,点击查找按钮,显示所查联系 +ContactColumn.HOMENUM+"text," +ContactColumn.ADDRESS+"text," +ContactColumn.EMAIL+"text," +ContactColumn.BLOG+"text);"; publicDBHelper(Contextcontext) { super(context,DATABASE_NAME,null,DATABASE_VERSION); } publicvoidonCreate(SQLiteDatabasedb) { db.execSQL(DATABASE_CREATE); } publicvoidonUpgrade(SQLiteDatabasedb,intoldVersion,intnewVersion) { db.execSQL("DROPTABLEIFEXISTS"+CONTACTS_TABLE); onCreate(db); }}//URI类型转换 publicStringgetType(Uriuri) { switch(uriMatcher.match(uri)) { caseCONTACTS: return"vnd.android.cursor.dir/vnd.yarin.android.mycontacts"; caseCONTACT_ID: return"vnd.android.cursor.item/vnd.yarin.android.mycontacts"; default: thrownewIllegalArgumentException("UnsupportedURI:"+uri); } }//删除指定数据列 @Override publicintdelete(Uriuri,Stringwhere,String[]selectionArgs) { intcount; switch(uriMatcher.match(uri)) { caseCONTACTS: count=contactsDB.delete(CONTACTS_TABLE,where,selectionArgs); break; caseCONTACT_ID: StringcontactID=uri.getPathSegments().get(1); count=contactsDB.delete(CONTACTS_TABLE, ContactColumn._ID +"="+contactID +(!TextUtils.isEmpty(where)?"AND("+where+")":""), selectionArgs); break; default: thrownewIllegalArgumentException("UnsupportedURI:"+uri); } getContext().getContentResolver().notifyChange(uri,null); returncount; }//插入数据 publicUriinsert(Uriuri,ContentValuesinitialValues) { if(uriMatcher.match(uri)!=CONTACTS) { thrownewIllegalArgumentException("UnknownURI"+uri); } ContentValuesvalues; if(initialValues!=null) { values=newContentValues(initialValues); Log.e(TAG+"insert","initialValuesisnotnull"); } else { values=newContentValues(); } //设置默认值 if(values.containsKey(ContactColumn.NAME)==false) { values.put(ContactColumn.NAME,""); } if(values.containsKey(ContactColumn.MOBILENUM)==false) { values.put(ContactColumn.MOBILENUM,""); } if(values.containsKey(ContactColumn.HOMENUM)==false) { values.put(ContactColumn.HOMENUM,""); } if(values.containsKey(ContactColumn.ADDRESS)==false) { values.put(ContactColumn.ADDRESS,""); } if(values.containsKey(ContactColumn.EMAIL)==false) { values.put(ContactColumn.EMAIL,""); } if(values.containsKey(ContactColumn.BLOG)==false) { values.put(ContactColumn.BLOG,""); } Log.e(TAG+"insert",values.toString()); longrowId=contactsDB.insert(CONTACTS_TABLE,null,values); if(rowId>0) { UrinoteUri=ContentUris.withAppendedId(CONTENT_URI,rowId); getContext().getContentResolver().notifyChange(noteUri,null); Log.e(TAG+"insert",noteUri.toString()); returnnoteUri; } thrownewSQLException("Failedtoinsertrowinto"+uri); }//更新数据库 publicintupdate(Uriuri,ContentValuesvalues,Stringwhere,String[]selectionArgs) { intcount; Log.e(TAG+"update",values.toString()); Log.e(TAG+"update",uri.toString()); Log.e(TAG+"update:match",""+uriMatcher.match(uri)); switch(uriMatcher.match(uri)) { caseCONTACTS: Log.e(TAG+"update",CONTACTS+""); count=contactsDB.update(CONTACTS_TABLE,values,where,selectionArgs); break; caseCONTACT_ID: StringcontactID=uri.getPathSegments().get(1); Log.e(TAG+"update",contactID+""); count=contactsDB.update(CONTACTS_TABLE,values,ContactColumn._ID+"="+contactID +(!TextUtils.isEmpty(where)?"AND("+where+")":""),selectionArgs); break; default: thrownewIllegalArgumentException("UnsupportedURI:"+uri); } getContext().getContentResolver().notifyChange(uri,null); returncount; }}publicbooleanonPrepareOptionsMenu(Menumenu) { super.onPrepareOptionsMenu(menu); finalbooleanhaveItems=getListAdapter().getCount()>0; if(haveItems) { Uriuri=ContentUris.withAppendedId(getIntent().getData(),getSelectedItemId()); Intent[]specifics=newIntent[2]; specifics[0]=newIntent(Intent.ACTION_EDIT,uri); specifics[1]=newIntent(Intent.ACTION_VIEW,uri); MenuItem[]items=newMenuItem[2]; //添加满足条件的菜单 Intentintent=newIntent(null,uri); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE,0,0,null,specifics,intent,0,items); if(items[0]!=null) { //编辑联系人 items[0].setShortcut('1','e').setIcon(R.drawable.edituser).setTitle(R.string.editor_user); } if(items[1]!=null) { //查看联系人 items[1].setShortcut('2','f').setTitle(R.string.view_user).setIcon(R.drawable.viewuser); } } else { menu.removeGroup(Menu.CATEGORY_ALTERNATIVE); } returntrue; }<?xmlversion="1.0"encoding="utf-8"?><manifestxmlns:android="/apk/res/android"package="com.yarin.android.MyContacts"android:versionCode="1"android:versionName="1.0"><applicationandroid:icon="@drawable/icon"android:label="@string/app_name"> <providerandroid:name="ContactsProvider"android:authorities="vider.ContactsProvider"/><activityandroid:name=".MyContacts"android:label="@string/app_name"><intent-filter><actionandroid:name="ent.action.MAIN"/><categoryandroid:name="ent.category.LAUNCHER"/></intent-filter></activity><activityandroid:name=".ContactEditor"android:label="@string/editor_user"><intent-filter><actionandroid:name="ent.action.EDIT"/><categoryandroid:name="ent.category.DEFAULT"/><dataandroid:mimeType="vnd.android.cursor.item/vnd.yarin.android.mycontacts"/></intent-filter><intent-filter><actionandroid:name="ent.action.INSERT"/><categoryandroid:name="ent.category.DEFAULT"/><dataandroid:mimeType="vnd.android.cursor.dir/vnd.yarin.android.mycontacts"/></intent-filter></activity><activityandroid:name=".ContactView"android:label="@string/view_user"><intent-filter>
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 异体肾移植状态的健康教育
- 骨科实习护理心得体会
- 安全生产心得体会范文
- 2×660MW超超临界燃煤空冷机组新建工程400V低压开关柜(主厂房)技术协议
- 运筹学A-第1章线性规划
- 河南省部分重点高中2023-2024学年高三3月模拟考试理综生物试题
- 小工程施工合同书
- 药品网络销售监管管理办法培训试题及答案
- 土方回填 工程监理旁站用表
- 旅游产业合作协议书
- 2024年食品行业技能鉴定考试-学校食堂从业人员笔试参考题库含答案
- 建筑幕墙工程(铝板、玻璃、石材)监理实施细则(全面版)
- 五年级下册科学实验报告2022年新苏教版
- 第6课+欧洲的思想解放运动【中职专用】《世界历史》(高教版2023基础模块)
- 《中国陶瓷史》课件-24各种色釉元代瓷
- 校园网络视频数字监控系统设计方案
- 2023版静脉治疗行标解读
- 洛带古镇文旅古镇全年运营规划方案
- MOOC 产品创新设计与实践-江南大学 中国大学慕课答案
- 信息系统集成行业发展前景与机遇研究报告
- 2024新高考语文高考复习 名篇名句默写(含答案)
评论
0/150
提交评论