目录
1. 基于Android的通讯录系统设计与实现 3
1.1 系统需求分析 3
1.1.1操作可行性 3
1.1.2功能分析 3
1.2 系统总体设计 3
1.2.1UML类图 3
1.3 系统测试 3
1.3.1 首页界面 3
1.3.2立即注册界面 4
1.3.3忘记密码界面 4
1.3.4修改密码界面 5
1.3.5登录界面 5
1.3.6查询数据 6
1.3.7修改数据 7
1.3.8添加数据 7
1.3.9删除数据 8
1.4系统实现 8
1.4.1清单文件 8
1.4.2主要代码 9
(1)activity_main.xml 9
(2)dressbook.xml 12
(3)SQLMainActivity.java 16
1.5技术说明 20
2. 课程设计总结 20
2.1 总结 20
1. 基于Android的通讯录系统设计与实现
1.1 系统需求分析
1.1.1操作可行性
系统的操作可行性是一个系统成功与否的关健,在很多系统中操作的合理性经常成为用户讨论的焦点,所以说系统设计的合理性既是需要考虑的关键也是对用户选择此系统的主要吸引力。
该系统的功能不能单一,这样既保证了用户的部分需求,也不会显得杂乱。
1.1.2功能分析
本系统“用户信息管理与学校”包含首页、用户注册、用户登录、找回密码、验证、密码重置、通讯录添加,删除,修改查询等功能。
1.2 系统总体设计
1.2.1UML类图
1.3 系统测试
1.3.1 首页界面
实现首界面的搭建;
1.3.2立即注册界面
实现立即注册的界面的搭建;
实现界面跳转。
1.3.3忘记密码界面
实现忘记密码界面的搭建;
实现界面跳转。
1.3.4修改密码界面
实现修改密码界面的搭建;
实现界面跳转功能;
1.3.5登录界面
实现登录界面的搭建;
实现登录按钮的点击事件;
实现界面跳转功能;
1.3.6查询数据
1.3.7修改数据
1.3.8添加数据
1.3.9删除数据
1.4系统实现
1.4.1清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.theaddressbook"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/w1"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".zhuceActivity"
>
</activity>
<activity
android:name=".MimaMainActivity"
android:label="@string/title_activity_mima_main" >
</activity>
<activity
android:name=".XiugaipsMainActivity"
android:label="@string/title_activity_xiugaips_main" >
</activity>
<activity
android:name=".SQLMainActivity"
android:label="@string/title_activity_sqlmain" >
</activity>
</application>
</manifest>
1.4.2主要代码
主要布局代码
(1)activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/iv"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:background="@drawable/head"/>
<LinearLayout
android:id="@+id/ll_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#ffffff">
<TextView
android:id="@+id/tv_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="账号:"
android:textColor="#000"
android:textSize="18sp"/>
<EditText
android:id="@+id/et_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:padding="8dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_psw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="8dp"
android:background="#ffffff">
<TextView
android:id="@+id/tv_psw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="密码:"
android:textColor="#000"
android:textSize="18sp"/>
<EditText
android:id="@+id/et_psw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:inputType="textPassword"
android:padding="8dp"/>
</LinearLayout>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="25dp"
android:background="#87CEEB"
android:text="登录"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="18sp"
android:onClick="Login"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_register"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:padding="8dp"
android:text="立即注册"
android:background="@null"
android:textSize="14sp"
android:textColor="#686868"
android:onClick="Sign" />
<Button
android:id="@+id/btn_find_psw"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:padding="8dp"
android:text="找回密码?"
android:textSize="14sp"
android:textColor="#686868"
android:background="@null"
android:onClick="Password"/>
</LinearLayout>
</LinearLayout>
(2)dressbook.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6E6E6"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@android:color/white"
android:orientation="horizontal">
<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@null"
android:hint="请输入联系人"
android:padding="10dp"
android:maxLines="1"
android:textStyle="italic"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@android:color/white"
android:orientation="horizontal">
<EditText
android:id="@+id/et_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@null"
android:padding="10dp"
android:hint="请输入电话号码"
android:maxLines="1"
android:textStyle="italic"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@android:color/white"
android:orientation="horizontal">
<EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:hint="请输入联系人地址"
android:background="@null"
android:padding="10dp"
android:maxLines="1"
android:textStyle="italic"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="添加"/>
<Button
android:id="@+id/query"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查询"
android:layout_marginLeft="170dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
>
<Button
android:id="@+id/update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="修改"/>
<Button
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="删除"
android:layout_marginLeft="170dp"/>
</LinearLayout>
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff">
</ListView>
</LinearLayout>
(3)SQLMainActivity.java
package com.example.theaddressbook;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
public class SQLMainActivity extends Activity implements View.OnClickListener {
private EditText et_name,et_price,et_number;
private ListView listView;
private String name,price,number;
private MyHelper myHelper;
private SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dressbook);
et_name = (EditText)findViewById(R.id.et_name);
et_price = (EditText)findViewById(R.id.et_price);
et_number = (EditText) findViewById(R.id.et_number);
listView = (ListView)findViewById(R.id.listView);
Button add = (Button)findViewById(R.id.add);
Button query =(Button) findViewById(R.id.query);
Button update =(Button) findViewById(R.id.update);
Button delete = (Button)findViewById(R.id.delete);
add.setOnClickListener(this);
query.setOnClickListener(this);
update.setOnClickListener(this);
delete.setOnClickListener(this);
myHelper = new MyHelper(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.add:
db = myHelper.getWritableDatabase();
name = et_name.getText().toString();
price = et_price.getText().toString();
number = et_number.getText().toString();
ContentValues values = new ContentValues(); //创建ContentValues对象
values.put("name", name); //将数据添加到ContentValues对象
values.put("price", price);
values.put("number", number);
db.insert("cart", null, values);
db.close();
Toast.makeText(this, "信息已添加", Toast.LENGTH_SHORT).show();
break;
case R.id.query:
Log.e("yanwenhua","123");
List<CartBean> list = new ArrayList();
db = myHelper.getWritableDatabase();
Cursor cursor = db.query("cart", null, null, null, null,
null, null);
if (cursor.getCount() == 0) {
Toast.makeText(this, "没有数据", Toast.LENGTH_SHORT).show();
} else {
while (cursor.moveToNext()) {
CartBean cartBean = new CartBean();
int nameIndex = cursor.getColumnIndex("name");
int priceIndex = cursor.getColumnIndex("price");
int numberIndex = cursor.getColumnIndex("number");
String name = cursor.getString(nameIndex);
String price = cursor.getString(priceIndex);
String number = cursor.getString(numberIndex);
Log.e("yanwenhua","cursor.getCount();--"+cursor.getCount()+"name-"+name+" "+price+" "+number);
cartBean.setName(name);
cartBean.setPrice(price);
cartBean.setNumber(number);
list.add(cartBean);
}
CartAdapter adapter = new CartAdapter(SQLMainActivity.this,list);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
cursor.close();
db.close();
break;
case R.id.update:
name = et_name.getText().toString();
price = et_price.getText().toString();
number = et_number.getText().toString();
db = myHelper.getWritableDatabase();
values = new ContentValues(); // 要修改的数据
values.put("number",number);
values.put("price",price);
db.update("cart", values, "name=?",
new String[]{name}); // 更新并得到行数
db.close();
Toast.makeText(this, "信息已修改", Toast.LENGTH_SHORT).show();
break;
case R.id.delete:
db = myHelper.getWritableDatabase();
db.delete("cart", null, null);
List<CartBean> list2 = new ArrayList();
CartAdapter adapter = new CartAdapter(SQLMainActivity.this,list2);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
db.close();
Toast.makeText(this, "信息已删除", Toast.LENGTH_SHORT).show();
break;
}
}
}
1.5技术说明
主要使用技术 |
使用地方 |
ListView |
联系人信息列表 |
SQLite |
联系人信息的保存等 |
2. 课程设计总结
2.1 总结
不管做什么,我们都要相信自己,不能畏惧,不能怕遇到困难,什么都需要去尝试,有些你开始认为很难的事在你尝试之后你可能会发现原来她并没有你以前觉得的那样,自己也是可以的。如果没有自信,没有目标,没有信心就不可能把事情做好,当其他人都在迷茫的时候,自己一定要坚信目标,大学毕业出去即面临找工作,从学习这个专业,到以后从事这方面的工作都需要不断地去学习去实践,这次实践可以给我们敲一个警钟,我们面临毕业,面临择业,需要这些实践经验,在困难面前要勇于尝试,这是这次课程设计给我的最大感想!
以上基本是这次课设的体会了,设计进行的非常艰难,编码非常不容易,才发现做一个项目最重要的不在于如何实现,而是实现之前的需求分析和模块设计。创新很难,有些流行的系统其实现并不难,难的在于对市场的分析和准确定位。设计,是一个任重道远的过程。