嗨,我有以下代碼,它基本上填充手機的聯繫人列表並將其顯示在列表視圖中。從填充列表視圖中選擇電話簿的聯繫人
listView = (ListView) layout.findViewById(R.id.listView);
// GET PHONE BOOK'S CONTENT
cursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
null,
null,
null);
startManagingCursor(cursor);
String [] entries = {
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone._ID
};
int [] temp = {
android.R.id.text1,
android.R.id.text2
};
SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(mContext,
android.R.layout.simple_list_item_2,
cursor, entries, temp);
listView.setAdapter(listAdapter);
if(listView != null){
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Log.w("TAG", "SELECTING: " + listView.getAdapter().getItem(position).toString());
/*
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.fromParts("sms", listView.getAdapter().getItem(position).toString(), null));
i.putExtra("sms_body", "Some message goes here.");
i.setType("vnd.android-dir/mms-sms");
startActivity(i);
*/
}
});
}
我想要做的是輸出聯繫人的名稱以及關聯的電話號碼(主號碼)。因此,我可以創建一個新的意圖,根據電話號碼和我的聯繫人的姓名預先定義短信。
任何人都可以告訴我如何做到這一點?謝謝
謝謝,但我想你誤解了我的意思。我試圖輸出(即在Logcat上顯示)名稱和在列表視圖上點擊的項目的電話號碼。 – Jeremy
請現在檢查代碼我希望此代碼可以幫助您 –