Android 通訊錄 完整示例程式設計詳解

2021-08-26 13:02:56 字數 4241 閱讀 7960

第三部分 通訊錄

該例實現了瀏覽聯絡人、新增聯絡人、刪除聯絡人、編輯聯絡人、檢視聯絡人,當找到乙個聯絡人後,可以呼叫或者傳送訊息給該聯絡人。

下例體現了ui設計、資料庫的綜合操作、動態選單的使用以及各種許可權的註冊。

public class contactcolumn implements basecolumns

//列名

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 =;

} public class dbhelper extends sqliteopenhelper

public void oncreate(sqlitedatabase db)

public void onupgrade(sqlitedatabase db, int oldversion, int newversion)

}public class contacteditor extends activityelse if (intent.action_insert.equals(action))

setresult(result_ok, (new intent()).setaction(muri.tostring()));

}else

setcontentview(r.layout.editorcontacts);

nametext = (edittext) findviewbyid(r.id.edittext01);

mobiletext = (edittext) findviewbyid(r.id.edittext02);

hometext = (edittext) findviewbyid(r.id.edittext03);

addresstext = (edittext) findviewbyid(r.id.edittext04);

emailtext = (edittext) findviewbyid(r.id.edittext05);

blogtext = (edittext) findviewbyid(r.id.edittext06);

okbutton = (button)findviewbyid(r.id.button01);

cancelbutton = (button)findviewbyid(r.id.button02);

okbutton.setonclicklistener(new onclicklistener()else

}});

cancelbutton.setonclicklistener(new onclicklistener()else

}});

log.e(tag+":oncreate", muri.tostring());

// 獲得並儲存原始聯絡人資訊

mcursor = managedquery(muri, contactcolumn.projection, null, null, null);

mcursor.movetofirst();

log.e(tag, "end of oncreate()");

}protected void onresume()else if (mstate == state_insert)

string name = mcursor.getstring(contactcolumn.name_column);

string moblie = mcursor.getstring(contactcolumn.mobilenum_column);

string home = mcursor.getstring(contactcolumn.homenum_column);

string address = mcursor.getstring(contactcolumn.address_column);

string email = mcursor.getstring(contactcolumn.email_column);

string blog = mcursor.getstring(contactcolumn.blog_column);

nametext.settext(name);

mobiletext.settext(moblie);

hometext.settext(home);

addresstext.settext(address);

emailtext.settext(email);

blogtext.settext(blog);

}else

} protected void onpause()else}}

public boolean oncreateoptionsmenu(menu menu) else

return true;

}public boolean onoptionsitemselected(menuitem item)

return super.onoptionsitemselected(item);

}private void deletecontact()

}private void cancelcontact()

setresult(result_canceled);

finish();

}private void updatecontact()

setresult(result_canceled);

finish();

}private void backupcontact()

setresult(result_canceled);

finish();}}

public class contactview extends activity

protected void onresume()else

}public boolean oncreateoptionsmenu(menu menu)

public boolean onoptionsitemselected(menuitem item)

return super.onoptionsitemselected(item);

}private void deletecontact()}}

res.layout.eidtorcontacts.xml

<?xml version="1.0" encoding="utf-8"?>

"android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/bg">

res.layout.viewuser.xml

<?xml version="1.0" encoding="utf-8"?>

"android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:stretchcolumns="1"

android:background="@drawable/bg">

簡易通訊錄初編

linux中清空輸入緩衝區最簡便的方法 再來看看linux對fflush stdin 的說法 man 3 fflush 如果對fflush傳入乙個輸入流,會清除已經從輸入流中取出但還沒有交給程式的資料 連輸入流都沒提到。說明glibc實現中的fflush要麼對輸入流什麼都沒乾,要麼幹了些對外部完全沒...

Android讀取通訊錄資料

第一步,配置許可權 如果需要儲存,還需要儲存許可權 第二步,編寫聯絡人獲取工具類contractsutil public class contractsutil 根據uri查詢相應的contentprovider,cursor為獲取到的資料集 cursor cursor context.getcon...

單鏈表通訊錄 通訊錄2 0

單鏈表通訊錄 通訊錄2.0 標頭檔案 ifndef address h define address h include include include define success 10000 define failure 10001 define true 10002 define false ...