安卓通讯录实训报告.doc

上传人:jian****018 文档编号:8815605 上传时间:2020-04-01 格式:DOC 页数:10 大小:399.50KB
返回 下载 相关 举报
安卓通讯录实训报告.doc_第1页
第1页 / 共10页
安卓通讯录实训报告.doc_第2页
第2页 / 共10页
安卓通讯录实训报告.doc_第3页
第3页 / 共10页
点击查看更多>>
资源描述
安卓实训设计报告安卓通讯录设计题目: 安卓通讯录 班 级: 姓 名: 学 号: 指导老师: 日 期: 2012年6月7日 内容要求一、题目分析,功能要求。 1.1 实验目的 熟悉Android软件开发的基本架构 利用Eclipse和ADT插件设计通讯录 1.2 功能本手机通讯录工具主要实现五大功能:联系人的查询:字段查询,分组查询,字母排序查询;增加、删除联系人以及修改联系人信息;导入、导出联系人;发送联系人信息;设置。二、实验设计2.1 UI设计 我们用一个ListView来显示整个通讯录,其中用TextView显示每一记录,他们的xml文件分别为:main.xml(通讯录主界面),addres.xml(添加联系人界面),list_item.xml(浏览联系人界面),find.xml(查找联系人界面)。2.2功能的设计 为了在主界面中浏览联系人的信息,并且创建主要菜单栏,我们设计了MainActivity类,主要用于显示联系人信息和菜单栏,通过菜单栏,实现通讯录的相关功能。AddressBook类主要是为了实现联系人的添加功能,并且实现信息的保存后跳转到主界面。Findactivity类主要是为了实现联系人的查找功能,输入联系人的姓名,点击查找按钮,显示所查联系人的相关信息。3、 实验程序四、实验效果图五、总结通过设计该通讯录,主要学习了UI设计、数据库的综合操作、动态菜单的使用以及各种权限的注册。通过本次设计,使我对Android平台的数据库操作有了更进一步的理解,同时也对Android系统有了更深入的了解。附录一/定义数据public class ContactColumn implements BaseColumnspublic ContactColumn()/列名public static final String NAME = name;/姓名public static final String MOBILENUM = mobileNumber;/移动电话public static final String HOMENUM = homeNumber;/家庭电话public static final String ADDRESS = address;/地址public static final String EMAIL = email;/邮箱public static final String BLOG = blog;/博客/列 索引值public static final int _ID_COLUMN = 0;public static final int NAME_COLUMN = 1;public static final int MOBILENUM_COLUMN = 2;public static final int HOMENUM_COLUMN = 3;public static final int ADDRESS_COLUMN = 4;public static final int EMAIL_COLUMN = 5;public static final int BLOG_COLUMN = 6;/查询结果public static final String PROJECTION =_ID,NAME,MOBILENUM,HOMENUM,ADDRESS,EMAIL,BLOG,;public class DBHelper extends SQLiteOpenHelperpublic static final String DATABASE_NAME = mycontacts.db;/数据库名public static final int DATABASE_VERSION = 2; /版本public static final String CONTACTS_TABLE = contacts; /表名/创建表private static final String DATABASE_CREATE = CREATE TABLE + CONTACTS_TABLE + (+ ContactColumn._ID+ integer primary key autoincrement,+ ContactColumn.NAME+ text,+ ContactColumn.MOBILENUM+ text,+ ContactColumn.HOMENUM+ text,+ ContactColumn.ADDRESS+ text,+ ContactColumn.EMAIL+ text,+ ContactColumn.BLOG+ text);public DBHelper(Context context)super(context, DATABASE_NAME, null, DATABASE_VERSION);public void onCreate(SQLiteDatabase db)db.execSQL(DATABASE_CREATE);public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)db.execSQL(DROP TABLE IF EXISTS + CONTACTS_TABLE);onCreate(db);/ URI类型转换public String getType(Uri uri)switch (uriMatcher.match(uri)case CONTACTS:return vnd.android.cursor.dir/vnd.yarin.android.mycontacts;case CONTACT_ID:return vnd.android.cursor.item/vnd.yarin.android.mycontacts;default:throw new IllegalArgumentException(Unsupported URI: + uri);/ 删除指定数据列Overridepublic int delete(Uri uri, String where, String selectionArgs)int count;switch (uriMatcher.match(uri)case CONTACTS:count = contactsDB.delete(CONTACTS_TABLE, where, selectionArgs);break;case CONTACT_ID:String contactID = uri.getPathSegments().get(1);count = contactsDB.delete(CONTACTS_TABLE, ContactColumn._ID + = + contactID + (!TextUtils.isEmpty(where) ? AND ( + where + ) : ), selectionArgs);break;default:throw new IllegalArgumentException(Unsupported URI: + uri);getContext().getContentResolver().notifyChange(uri, null);return count;/ 插入数据public Uri insert(Uri uri, ContentValues initialValues)if (uriMatcher.match(uri) != CONTACTS)throw new IllegalArgumentException(Unknown URI + uri);ContentValues values;if (initialValues != null)values = new ContentValues(initialValues);Log.e(TAG + insert, initialValues is not null);elsevalues = new ContentValues();/ 设置默认值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();long rowId = contactsDB.insert(CONTACTS_TABLE, null, values);if (rowId 0)Uri noteUri = ContentUris.withAppendedId(CONTENT_URI, rowId);getContext().getContentResolver().notifyChange(noteUri, null);Log.e(TAG + insert, noteUri.toString();return noteUri;throw new SQLException(Failed to insert row into + uri);/ 更新数据库public int update(Uri uri, ContentValues values, String where, String selectionArgs)int count;Log.e(TAG + update, values.toString();Log.e(TAG + update, uri.toString();Log.e(TAG + update :match, + uriMatcher.match(uri);switch (uriMatcher.match(uri)case CONTACTS:Log.e(TAG + update, CONTACTS + );count = contactsDB.update(CONTACTS_TABLE, values, where, selectionArgs);break;case CONTACT_ID:String contactID = 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:throw new IllegalArgumentException(Unsupported URI: + uri);getContext().getContentResolver().notifyChange(uri, null);return count;public boolean onPrepareOptionsMenu(Menu menu)super.onPrepareOptionsMenu(menu);final boolean haveItems = getListAdapter().getCount() 0;if (haveItems)Uri uri = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId();Intent specifics = new Intent2;specifics0 = new Intent(Intent.ACTION_EDIT, uri);specifics1 = new Intent(Intent.ACTION_VIEW, uri);MenuItem items = new MenuItem2;/添加满足条件的菜单Intent intent = new Intent(null, uri);intent.addCategory(Intent.CATEGORY_ALTERNATIVE);menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items);if (items0 != null)/编辑联系人items0.setShortcut(1, e).setIcon(R.drawable.edituser).setTitle(R.string.editor_user); if (items1 != null)/查看联系人items1.setShortcut(2, f).setTitle(R.string.view_user).setIcon(R.drawable.viewuser); elsemenu.removeGroup(Menu.CATEGORY_ALTERNATIVE);return true;
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 工作总结


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!