我有一个扩展LinearLayot的自定义视图,它有一个按钮和一个编辑文本。我想当用户点击按钮时,联系人书籍将打开,当用户选择一个号码时,该号码将显示在编辑文本中。我用了这段代码:
private void pickContact() {
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_CONTACT_REQUEST) {
if (resultCode == RESULT_OK) {
Uri contactUri = data.getData();
String[] projection = {Phone.NUMBER};
Cursor cursor = getContentResolver()
.query(contactUri, projection, null, null, null);
cursor.moveToFirst();
int column = cursor.getColumnIndex(Phone.NUMBER);
String number = cursor.getString(column);
}
}
}
因为我的类扩展了LinearLayout,所以我不能使用onActivityResult方法。任何身体都可以帮我吗? tahnks