最近写数据库,我就自己写了个带密码的个人通讯录,感觉sqlite特别好用,和mysql,sqlserver都一样,真是简单的关系型数据库,注意:开启数据库,cursor后一定要记得关闭close()掉,避免浪费资源。另外adapter的notifyDataSetChanged()这个方法也特别好用,就是数据库更新的时候,调用一下,baseAdapter中的getview就会重新加载一遍,这样界面就会更新数据,而不用onCreate()方法来更新,另外可以把notifyDataSetChanged()方法写在onResume()方法中,这样在两个activity跳转后按back 键也可以达到刷新界面的效果!

想要源码的可以留言,有问题可以留言,同时也欢迎指正我的纰漏;

转载请标明出处:http://blog.csdn.net/wdaming1986/article/details/6727032

另:csdn下载连接地址:http://download.csdn.net/source/3555843

程序启动后输入密码的界面:                                      第一次启动程序和点击修改密码界面:

                                           

点击确定,进入联系人列表界面:                                     点击menu菜单,有两个菜单键:

                                            

          单击每一个列表进入修改界面:                                    长按每一个联系人弹dialog删除记录:

                                            

下面看代码:

在com.cn.daming包下的类:

1、Login.java 程序的入口类

package com.cn.daming;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.cn.daming.databases.DBOpenHelper;
public class Login extends Activity {
private DBOpenHelper db;
private EditText et;
private Button login_button;
private String password;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
db = new DBOpenHelper(this);
password = db.getPwd();
db.close();
if(password.equals("")){
Intent intent = new Intent(Login.this,PasswordManage.class);
startActivity(intent);
finish();
return;
}
setContentView(R.layout.login);
et = (EditText)findViewById(R.id.login_password);
login_button = (Button)findViewById(R.id.note_login);
login_button.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
String input_pwd = et.getText().toString();
if(password.equals(input_pwd)){
Toast.makeText(Login.this, R.string.login_success, Toast.LENGTH_LONG).show();
Intent intent = new Intent(Login.this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}else{
Toast.makeText(Login.this, R.string.error_password, Toast.LENGTH_LONG).show();
et.setText("");
}
}
});
}
}

2、MainActivity.java类:程序listView列表显示类

package com.cn.daming;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
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.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.Toast;
import com.cn.daming.adapter.ContantsAdapter;
import com.cn.daming.databases.DBOpenHelper;
public class MainActivity extends Activity {
private DBOpenHelper dbOpenHelper;
private ContantsAdapter contantsAdapter;
private ListView dbListView;
private Cursor cursor;
final int MENU_ADD = Menu.FIRST;
final int MENU_CHANGE = Menu.FIRST+1;
private List<String> ids;
private List<String> names;
private List<String> phones;
AlertDialog dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dbOpenHelper = new DBOpenHelper(this);
dbListView = (ListView)findViewById(R.id.db_listview);
refreshDBOpenHelper();
dbListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
Intent intent= new Intent();
intent.putExtra("cmd", 0);
String contants_id = ids.get(position);//0代表查询联系人,1代表添加联系人
intent.putExtra("id", contants_id);
intent.setClass(MainActivity.this, DetailContantsActivity.class);
startActivity(intent);
}
});
dbListView.setOnItemLongClickListener(new OnItemLongClickListener(){
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int position, long arg3) {
dialog = new AlertDialog.Builder(MainActivity.this)
.setTitle("提示!!")
.setMessage("确定要删除这条记录?")
.setPositiveButton("确定",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
String contants_id = ids.get(position);
dbOpenHelper.deleteContants(contants_id);
dbOpenHelper.close();
Toast.makeText(MainActivity.this, "正在删除数据库,请稍后。。。", Toast.LENGTH_LONG).show();
refreshDBOpenHelper();
contantsAdapter.notifyDataSetChanged();
}
})
.setNegativeButton("取消",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dialog.dismiss();
}
}).show();
return false;
}
});
}
@Override
protected void onResume() {
refreshDBOpenHelper();
contantsAdapter.notifyDataSetChanged();
super.onResume();
}
public void refreshDBOpenHelper(){
cursor = dbOpenHelper.selectContants();
ids = new ArrayList<String>();
names = new ArrayList<String>();
phones = new ArrayList<String>();
int count = cursor.getCount();
if(count>0){
for(int i=0;i<count;i++){
cursor.moveToPosition(i);
ids.add(cursor.getString(0));
names.add(cursor.getString(1));
phones.add(cursor.getString(2));
}
}else{
Toast.makeText(this, R.string.not_dbcursor_values, Toast.LENGTH_SHORT).show();
}
contantsAdapter = new ContantsAdapter(this,names,phones);
dbListView.setAdapter(contantsAdapter);
cursor.close();
dbOpenHelper.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_ADD, 0, R.string.menu_add)
.setIcon(R.drawable.add);   //add - add_button
menu.add(0, MENU_CHANGE, 0, R.string.menu_change)
.setIcon(R.drawable.modify);        //add -add_change_password
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){       //
case MENU_ADD:          //press change add button
Intent add_intent= new Intent(this,DetailContantsActivity.class);
add_intent.putExtra("cmd", 1);
startActivity(add_intent);
break;
case MENU_CHANGE:   //press change password button
Intent change_password_intent = new Intent(MainActivity.this,PasswordManage.class);
startActivityForResult(change_password_intent,0);
break;
}
return super.onOptionsItemSelected(item);
}
}

3、PasswordManage.java,密码设置类:

package com.cn.daming;
import com.cn.daming.databases.DBOpenHelper;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class PasswordManage extends Activity {
private EditText et1;
private EditText et2;
private Button button;
private DBOpenHelper db;
private int CHANGE_PWD_SUCCESS = 100;
public void onCreate(Bundle bundle){
super.onCreate(bundle);
db = new DBOpenHelper(this);
setContentView(R.layout.password_manage);
et1 = (EditText)findViewById(R.id.new_password);
et2 = (EditText)findViewById(R.id.repeat_password);
button = (Button)findViewById(R.id.save_password);
button.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
String new_pwd = et1.getText().toString();
String repeat_pwd = et2.getText().toString();
if(new_pwd==null||new_pwd.equals("")){
Toast.makeText(PasswordManage.this, R.string.password_is_null, Toast.LENGTH_LONG).show();
}else{
if(new_pwd.equals(repeat_pwd)){
if(db.getPwd().equals("")){
db.insertPwd(new_pwd);
Toast.makeText(PasswordManage.this, R.string.password_set_success, Toast.LENGTH_LONG).show();
toNoteList();
}else{
db.updatePwd(new_pwd);
Toast.makeText(PasswordManage.this, R.string.password_change_success, Toast.LENGTH_LONG).show();
PasswordManage.this.setResult(CHANGE_PWD_SUCCESS);
PasswordManage.this.finish();
}
}else{
Toast.makeText(PasswordManage.this, R.string.password_isnot_equal, Toast.LENGTH_LONG).show();
}
}
}
});
}
public void toNoteList(){
Toast.makeText(PasswordManage.this, R.string.password_set_success, Toast.LENGTH_LONG);
Intent intent = new Intent(PasswordManage.this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
}

4、DetailContantsActivity。java类,每一条记录,联系人的类:

package com.cn.daming;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import com.cn.daming.databases.DBOpenHelper;
public class DetailContantsActivity extends Activity{
Cursor cursor;
DBOpenHelper dbOpenHelper;
int id = -1;
int [] textIds ={
R.id.etName,
R.id.etPhone,
R.id.etMobile,
R.id.etEmail,
R.id.etPost,
R.id.etAddr,
R.id.etComp
};
EditText [] textArray;
ImageButton saveButton; //save Button
int status = -1; //0表示查看信息,1表示添加联系人,2表示修改联系人
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contants_detail);
textArray = new EditText[textIds.length];
for(int i=0;i<textIds.length;i++){
textArray[i] = (EditText)findViewById(textIds[i]);
}
initSaveImageButton();
dbOpenHelper = new DBOpenHelper(this);
Intent intent = getIntent();
status = intent.getExtras().getInt("cmd");
switch(status){
case 0:
String contants_id = intent.getExtras().getString("id");
cursor = dbOpenHelper.getContants(contants_id);
int count = cursor.getCount();
if(count == 0){
Toast.makeText(this, "对不起,没有找到指定的联系人!", Toast.LENGTH_LONG).show();
}
else{
cursor.moveToFirst();
textArray[0].setText(cursor.getString(1));   //设置姓名框中的内容
textArray[1].setText(cursor.getString(2));   //设置固话框中的内容
textArray[2].setText(cursor.getString(3));   //设置手机号码框中的内容
textArray[3].setText(cursor.getString(4));   //设置电子邮件框中的内容
textArray[4].setText(cursor.getString(5));   //设置电子邮件框中的内容
textArray[5].setText(cursor.getString(6));   //设置电子邮件框中的内容
textArray[6].setText(cursor.getString(7));   //设置电子邮件框中的内容
}
cursor.close();
dbOpenHelper.close();
break;
case 1:     //新建详细人信息
for(EditText et:textArray){
et.getEditableText().clear();  //清空各个EditText控件中内容
}
break;
}
}
public void initSaveImageButton()
{
saveButton = (ImageButton)findViewById(R.id.detailSave);
saveButton.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
String [] strArray = new String[textArray.length];
for(int i=0;i<strArray.length;i++){
strArray[i] = textArray[i].getText().toString().trim(); //获得用户输入的信息数组
}
if(strArray[0].equals("") || strArray[1].equals("")){
Toast.makeText(DetailContantsActivity.this, "对不起,请将姓名和电话填写完整!", Toast.LENGTH_LONG).show();
}else{
switch(status){  //判断当前的状态
case 0:    //查询联系人详细信息时按下保存
updateContact(strArray);  //更新联系人信息
break;
case 1:    //新建联系人时按下保存按钮
insertContact(strArray);  //插入联系人信息
break;
}
}
}
});
}
public void insertContact(String [] strArray){
long count = dbOpenHelper.insertContants(strArray);  //插入数据
dbOpenHelper.close();
if(count == -1){
Toast.makeText(this, "添加联系人失败!", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(this, "添加联系人成功!", Toast.LENGTH_LONG).show();
}
}
public void updateContact(String [] strArray){
int count = dbOpenHelper.updateContants(id+"", strArray); //更新数据库
dbOpenHelper.close();
if(count == 1){
Toast.makeText(this, "修改联系人成功!", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(this, "修改联系人失败!", Toast.LENGTH_LONG).show();
}
}
}

在com.cn.daming.databases包下面的类:
5、DBOpenHelper。java,数据库的类:

package com.cn.daming.databases;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBOpenHelper extends SQLiteOpenHelper{
private final static String DATABASE_NAME = "personal_contacts";
private final static int DATABASE_VERSION = 1;
private final static String TABLE_NAME = "contants";
public static final String ID="_id";       //ID
public static final String NAME="name";     //名称
public static final String PHONE="phone";  //固定电话
public static final String MOBILE="mobile";//手机号码
public static final String EMAIL="email";  //电子邮件地址
public static final String POST="post";     //邮政编码
public static final String ADDR="addr";     //通信地址
public static final String COMP="comp";     //公司
public final static String LOGIN_TABLE_NAME = "contantslogin";
public final static String LOGIN_USER = "admin";
public final static String LOGIN_PWD = "password";
public DBOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table "+TABLE_NAME+" ("
+ ID + " integer primary key autoincrement,"
+ NAME + " varchar,"
+ PHONE+" varchar,"
+ MOBILE + " varchar,"
+ EMAIL + " varchar,"
+ POST + " varchar,"
+ ADDR + " varchar,"
+ COMP + " varchar)";
db.execSQL(sql);
sql = "create table "+LOGIN_TABLE_NAME+" ("
+LOGIN_USER+" text, "
+LOGIN_PWD+" text )";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
String sql = "drop table if exists "+TABLE_NAME;
db.execSQL(sql);
sql = "drop table if exists "+LOGIN_TABLE_NAME;
db.execSQL(sql);
onCreate(db);
}
public Cursor selectContants(){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, null);
return cursor;
}
public long insertContants(String[] strArray){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(NAME, strArray[0]);
cv.put(PHONE, strArray[1]);
cv.put(MOBILE, strArray[2]);
cv.put(EMAIL, strArray[3]);
cv.put(POST, strArray[4]);
cv.put(ADDR, strArray[5]);
cv.put(COMP, strArray[6]);
return db.insert(TABLE_NAME, null, cv);
}
public void deleteContants(String id){
SQLiteDatabase db = this.getWritableDatabase();
String where = ID+"=?";
String[] whereValues = {id};
db.delete(TABLE_NAME, where, whereValues);
}
public int updateContants(String id,String[] strArray){
SQLiteDatabase db = this.getWritableDatabase();
String where = ID+"=?";
String[] whereValues = {id};
ContentValues cv = new ContentValues();
cv.put(NAME, strArray[0]);
cv.put(PHONE, strArray[1]);
cv.put(MOBILE, strArray[2]);
cv.put(EMAIL, strArray[3]);
cv.put(POST, strArray[4]);
cv.put(ADDR, strArray[5]);
cv.put(COMP, strArray[6]);
return db.update(TABLE_NAME, cv, where, whereValues);
}
public Cursor getContants(String id){
SQLiteDatabase db = this.getReadableDatabase();
String where = ID+"=?";
String[] whereValues = {id};
Cursor cursor = db.query(TABLE_NAME, null, where, whereValues, null, null, null);
return cursor;
}
public long insertPwd(String password){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(LOGIN_USER, LOGIN_USER);
cv.put(LOGIN_PWD, password);
return db.insert(LOGIN_TABLE_NAME, null, cv);
}
public int updatePwd(String password){
SQLiteDatabase db = this.getWritableDatabase();
String where = LOGIN_USER+"=?";
String[] whereValues = {LOGIN_USER};
ContentValues cv = new ContentValues();
cv.put(LOGIN_PWD, password);
return db.update(LOGIN_TABLE_NAME, cv, where, whereValues);
}
public String getPwd(){
SQLiteDatabase db = this.getReadableDatabase();
String where = LOGIN_USER+"=?";
String[] whereValues = {LOGIN_USER};
Cursor cursor = db.query(LOGIN_TABLE_NAME, null, where, whereValues, null, null, null);
if(cursor.moveToFirst()){
return cursor.getString(cursor.getColumnIndex(LOGIN_PWD));
}else{
return "";
}
}
}

在com.cn.daming.adapter包下的类:

6、ContantsAdapter。java,适配器类:

package com.cn.daming.adapter;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.cn.daming.R;
public class ContantsAdapter extends BaseAdapter {
private List<String> names;
private List<String> phones;
private LayoutInflater inflater;
private Context context;
public ContantsAdapter(Context context,List<String> names ,List<String> phones){
inflater = LayoutInflater.from(context);
this.names = names;
this.phones = phones;
this.context = context;
}
public int getCount() {
return names.size();
}
public Object getItem(int position) {
return names.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View view, ViewGroup group) {
ContantsHolder holder = new ContantsHolder();
if(view==null){
view = inflater.inflate(R.layout.contants_list_view, null);
holder.contansName = (TextView)view.findViewById(R.id.name_textview);
holder.contantsPhone = (TextView)view.findViewById(R.id.phone_textview);
view.setTag(holder);
}else{
holder = (ContantsHolder)view.getTag();
}
holder.contansName.setText(names.get(position));
holder.contantsPhone.setText(phones.get(position));
return view;
}
public class ContantsHolder
{
private TextView contansName;
private TextView contantsPhone;
}
}

布局文件

1、login。xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="10dip"
android:orientation="vertical"
android:background="@drawable/background"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/please_input_password"
android:textSize="24dip"
android:textStyle="bold"
android:textColor="@drawable/black"
android:layout_gravity="center"
/>
<EditText
android:id="@+id/login_password"
android:layout_width="250dip"
android:layout_height="wrap_content"
android:password="true"
android:layout_gravity="center"
android:layout_marginTop="15dip"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dip"
>
<Button
android:id="@+id/note_login"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="@string/ok"
/>
</LinearLayout>
</LinearLayout>

2、contants_detail.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
>                            <!-- 显示联系人姓名线性布局 -->
<TextView
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18px"
android:textColor="@color/text"
android:layout_gravity="left|center_vertical"
android:text="@string/contantsName"
/>
<EditText
android:id="@+id/etName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>                            <!-- 显示联系人固定电话的线性布局 -->
<TextView
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18px"
android:textColor="@color/text"
android:layout_gravity="center_vertical|left"
android:text="@string/contantsPhone"
/>
<EditText
android:id="@+id/etPhone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:phoneNumber="true"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>                                        <!-- 显示联系人手机号码的线性布局 -->
<TextView
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18px"
android:textColor="@color/text"
android:layout_gravity="left|center_vertical"
android:text="@string/contantsMobile"
/>
<EditText
android:id="@+id/etMobile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:phoneNumber="true"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>                                        <!-- 显示联系人电子邮件的线性布局 -->
<TextView
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18px"
android:textColor="@color/text"
android:layout_gravity="left|center_vertical"
android:text="@string/contantsEmail"
/>
<EditText
android:id="@+id/etEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>                                        <!-- 显示联系人邮编的线性布局 -->
<TextView
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18px"
android:textColor="@color/text"
android:layout_gravity="left|center_vertical"
android:text="@string/contantsPost"
/>
<EditText
android:id="@+id/etPost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>                                        <!-- 显示联系人通信地址的线性布局 -->
<TextView
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18px"
android:textColor="@color/text"
android:layout_gravity="left|center_vertical"
android:text="@string/contantsAddr"
/>
<EditText
android:id="@+id/etAddr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>                                        <!-- 显示联系人公司的线性布局 -->
<TextView
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18px"
android:textColor="@color/text"
android:layout_gravity="left|center_vertical"
android:text="@string/contantsComp"
/>
<EditText
android:id="@+id/etComp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<ImageButton
android:id="@+id/detailSave"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/save"
/>
</LinearLayout>

3、contants_list_view.xml,每一个list的item布局文件

<?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="horizontal">
<TextView
android:id="@+id/name_textview"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:textColor="#000000"
android:textSize="10pt"
/>
<TextView
android:id="@+id/phone_textview"
android:layout_width="165dip"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="10pt"
/>
</LinearLayout>

4、main.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/title"
android:textSize="24px"
android:textColor="@color/text"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/title"
/>
</LinearLayout>
<ListView
android:id="@+id/db_listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
/>
</LinearLayout>

5、password_manage.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/background"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="26dip"
android:padding="6dip"
android:paddingBottom="10dip"
android:textColor="@drawable/black"
android:text="@string/password_manage"
/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="10dip"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="50dip"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/new_password"
android:layout_gravity="right"
android:gravity="center"
android:textColor="#000000"
android:textSize="11pt"
/>
<EditText
android:id="@+id/new_password"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:password="true"
android:layout_marginLeft="20dip"
/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_marginTop="10dip"
android:gravity="center_vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/repeat_password"
android:layout_gravity="right"
android:gravity="center_vertical"
android:textColor="#000000"
android:textSize="11pt"
/>
<EditText
android:id="@+id/repeat_password"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:password="true"
android:layout_marginLeft="20dip"
/>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dip"
>
<Button
android:id="@+id/save_password"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:text="@string/ok"
android:textSize="16dip"
/>
</LinearLayout>
</LinearLayout>

values下的文件

1、string。xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, MainActivity!</string>
<string name="app_name">ContantsApp</string>
<string name="please_input_password">请输入大明通讯录密码:</string>
<string name="ok">确定</string>
<string name="login_success">恭喜,登陆成功!</string>
<string name="error_password">您输入的密码错误,请重新输入!</string>
<string name="password_manage">大明通讯录密码管理:</string>
<string name="new_password">新密码:</string>
<string name="repeat_password">再一次:</string>
<string name="password_is_null">输入密码为空,请输入密码!</string>
<string name="password_set_success">密码设置成功!</string>
<string name="password_change_success">密码修改成功!</string>
<string name="password_isnot_equal">两次输入的密码不一致,请重新输入密码!</string>
<string name="title">大明通讯录列表</string>
<string name="not_dbcursor_values">数据库中没有记录,请点击菜单新建通讯录!</string>
<string name="contantsName">姓名:</string>
<string name="contantsPhone">固定电话:</string>
<string name="contantsMobile">移动电话:</string>
<string name="contantsEmail">电子邮件:</string>
<string name="contantsPost">邮政编码:</string>
<string name="contantsAddr">通讯地址:</string>
<string name="contantsComp">公司地址:</string>
<string name="menu_add">增加</string>
<string name="menu_change">修改密码</string>
</resources>

2、color。xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="white">#FFFFFF</drawable>
<drawable name="black">#FF000000</drawable>
<drawable name="dackgray">#666666</drawable>
<drawable name="red">#FFFF0000</drawable>
<drawable name="blue">#FF0000FF</drawable>
<drawable name="yellow">#FFFFFF00</drawable>
<drawable name="green">#FF00FF00</drawable>
<color name="text">#000000</color>
<drawable name="changshise">#FFD19275</drawable>
</resources>

AndroidManifest.xml:

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cn.daming"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Login"
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=".MainActivity"></activity>
<activity android:name=".PasswordManage"></activity>
<activity android:name=".DetailContantsActivity"></activity>
</application>
</manifest>

Android 个人通讯录【安卓进化十四】相关推荐

  1. Android开发笔记(五十四)数据共享接口ContentProvider

    ContentProvider 前面几节介绍了进程间通信的几种方式,包括消息包级别的Messenger.接口调用级别的AIDL.启动页面/服务级别的Notification,还有就是本节这个数据库级别 ...

  2. Android 天气APP(三十四)语音搜索

    上一篇:Android 天气APP(三十三)语音播报 语音搜索 前言 正文 一.权限配置 二.用户体验优化 三.配置语音识别听写 四.语音搜索 五.地图天气添加语音搜索功能 六.城市搜索添加语音搜索功 ...

  3. Android开发笔记(七十四)布局文件优化

    include/merge 布局优化中常常用到include/merge标签,include的含义类似C代码中的include,意思是直接把指定布局片段包含进当前的布局文件.include适用于多个布 ...

  4. Android开发笔记(二十四)res目录的结构与配置

    res目录结构 res是Android项目工程中存放各类的目录,主要包括布局.图形与配置等等.res的子目录主要有: anim : 存放动画的描述文件 drawable : 存放各类图形的描述文件,包 ...

  5. Android开发艺术探索——第十四章:JNI和NDK编程

    JNI的意思是Java Native Interface(java本地接口),它是为了方便java调用C,C++等本地代码所封装的一层接口,我们都知道,JAVA的优点是跨平台,但是作为有蒂娜的同时,其 ...

  6. Android简易实战教程--第二十四话《画画板》

    今天完成一个画画板. 首先来个布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...

  7. 动画android,Android学习指南之二十四:Android动画的实现 上

    在Android系统中也能经常见到动画,那么如何实现动画效果呢?本文就来为大家介绍动画的实现方式. Android中动画的实现分两种方式,一种方式是补间动画Tween Animation,就是说你定义 ...

  8. 【Android测试】【第十四节】Appium——简述

    前言 同样的,这一篇我要介绍的也是一款UI自动化工具,地址:http://appium.io/ 第三方(非谷歌)研发的开源测试工具,说到这里也许有人会问 "为什么已经介绍了Uiautomat ...

  9. Android开发笔记(八十四)使用Properties读写属性值

    Properties概述 Java中的配置文件常为.properties文件,而Properties类便是读写此类文件的工具.属性文件有两种格式,一种是文本格式,其内容是"键=值" ...

最新文章

  1. 通俗易懂理解~图机器学习导论
  2. 深入理解MySQL执行过程及执行顺序
  3. 大规模落地:AI安防仍存两大痛点
  4. 【2018.4.14】模拟赛之二-ssl2392 蚂蚁【图论】
  5. 文件上传简介1---上传到指定的目录
  6. KVM系列之硬件管理
  7. 不要着急改代码,先想想--centos 6.8下编译安装tmux
  8. linux系统交换分区的文件格式是,【简答题】Red Hat Linux中,交换分区的文件系统类型是什么,光盘文件的文件系统类型是什么?...
  9. UCOS操作系统——中断和时间管理(七)
  10. java集成mpush 服务端SDK开发
  11. 从外观来看微型计算机由哪几个部分组成,福师11春学期《计算机应用基础》在线作业一...
  12. 图格 Pro for Mac(多功能照片拼图切图大师)
  13. JPA项目,Encountered a duplicated sql alias
  14. 重构--Introduce Parameter Object
  15. 一个完整推荐系统的设计实现
  16. 数据结构之线性表(顺序表和链表)
  17. c语言 topk算法,scala写算法-用小根堆解决topK
  18. 动作识别阅读笔记(三)《Temporal Segment Networks: Towards Good Practices for Deep Action Recognition》
  19. XXU邮箱,和客户端同步 pku
  20. 【kafka】kafka乱码问题

热门文章

  1. 转载自:【腾讯优测干货分享】Android5.0-6.0双卡适配指南
  2. hduoj -2570-简单的贪心算法入门
  3. 创业赢利模式之七产品金字塔模式
  4. python做gui好吗_使用Python制作一个铅笔类(Python GUI编程)
  5. adobe reader java_用JavaScript检测ie11中的Adobe Reader
  6. android7无法运行优酷,win7系统优酷客户端打不开的解决方法
  7. 计算机主机内部结构主要有哪几个,电脑硬件组成主要是哪几部分
  8. 利用LD_PRELOAD给glibc库函数加钩子
  9. 解决QQ聊天QQ秀咒语为什么我不能施放咒语/看不到咒语效果?
  10. 智能余额代还款APP软件开发