我是一个初学者到Android,我建立在当用户presses一个按钮的应用程序,显示存储在手机中的联系人。当他选择从联系人,我必须得到所选择的联系人姓名和电话号码。我试着用code,但只有被选中的联系人的姓名显示,而不是电话号码。
I am a beginner to android, i am building a application in which when the user presses a button, the contacts which is stored in the mobile are shown. When he selects a contact from that, i have to get the selected contact name and number. I tried using the code but only the name of the selected contact is shown and not the phone number.
public void readcontact(){
try {
Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts/people"));
startActivityForResult(intent, PICK_CONTACT);
} catch (Exception e) {
e.printStackTrace();
}
}
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
startManagingCursor(c);
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndexOrThrow(People.NAME));
String number = c.getString(c.getColumnIndexOrThrow(People.NUMBER));
perrsonname.setText(name);
Toast.makeText(this, name + " has number " + number, Toast.LENGTH_LONG).show();
}
}
break;
}
}
我还需要额外的号码(家庭,办公室等,)选定的联系人, 谁能帮我出这一点。这个建议是AP preciable。
I even need the additional number(home,office etc.,)of the selected contacts, Can anyone help me out with this. Suggestions on this is appreciable.
请参阅联系人应用程序中附带的Android源代码
Refer Contacts Application which comes with Android Source
上一篇:安卓:事件侦听器添加到每个项目在ListView侦听器、事件、项目、ListView
下一篇:有没有一种方法来禁用特定布局programmaticaly的所有项目?方法来、布局、项目、programmaticaly