I'm trying to add a QuickContactBadge
to a Recyclerview
.
Details:
I have a list where each item has a photo of a contact and some text.
What i want:
I would like to click on the image and bring up the QuickContactBadge. but it's not work for me.
Here's my code:
public class CoViewHolder extends RecyclerView.ViewHolder {
QuickContactBadge imageView;
TextView title, phone;
ImageView call;
String pho, nam;
int position;
boolean concal;
String contactID;
private static final int CONTACT_PICKER_RESULT = 0;
public CoViewHolder(View v, int viewType) {
super(v);
title = (TextView) v.findViewById(R.id.name);
phone = (TextView) v.findViewById(R.id.no);
call = (ImageView) v.findViewById(R.id.ccbtn);
imageView = (QuickContactBadge) v.findViewById(R.id.pic);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent ii = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(ii, CONTACT_PICKER_RESULT);
}
});
}
private void startActivityForResult(Intent ii, int contactPickerResult) {
if(contactPickerResult==RESULT_OK)
switch (contactPickerResult) {
case CONTACT_PICKER_RESULT:
Uri contactUri = ii.getData();
FrameLayout frameLayout = (FrameLayout)activity.findViewById(R.id.badge_holder_large);
QuickContactBadge badge = new QuickContactBadge(activity);
badge.assignContactUri(contactUri);
badge.setMode(ContactsContract.QuickContact.MODE_LARGE);
frameLayout.addView(badge);
Cursor cursorID = activity.getContentResolver().query(contactUri,
new String[]{ContactsContract.Contacts._ID}, null, null, null);
if (cursorID.moveToNext()) {
contactID = cursorID.getString(cursorID.getColumnIndex(ContactsContract.Contacts._ID));
}
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(activity.getContentResolver(),
ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, new Long(contactID)));
BufferedInputStream buf =new BufferedInputStream(input);
Bitmap my_btmp = BitmapFactory.decodeStream(buf);
if(my_btmp != null)
badge.setImageBitmap(my_btmp);
else
badge.setImageResource(R.drawable.image);
}
}
}