Frage

First the scenario:

I have a list where each item has a photo of a contact and some text. I would like to click on the image and bring up the QuickContactBadge. Badge is defined by the following XML snippet

<QuickContactBadge android:layout_height="wrap_content"
   android:layout_width="wrap_content" android:id="@+id/badge" 
   android:layout_alignParentBottom="true"></QuickContactBadge>

What I tried and failed:

  1. Define one reusable badge and reuse it for all cases. Both list and badge are placed into RelativeLayout
  2. Have one badge defined per each list item. The item uses RelativeLayout

What do I see:

Basically nothing. The code gets valid badge instance and then I apply the following logic

    contactPhoto.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            Log.d(TAG, "Image click");
            if (badge != null) {
                badge.assignContactFromEmail("johndoe@gmail.com", true);
                badge.setMode(ContactsContract.QuickContact.MODE_SMALL);
                badge.bringToFront();
            }
        }
    });

As I click I can step through the code in onClick handler yet the badge never comes up

The questions:

  1. Does QuickContactBadge have any placement logic? When I click on the image do I need to calculate badge position and readjust or is it built-in?
  2. Is it possible to achieve what I describe above (badge for images displayed in the list) and what I'm doing wrong (or missing)
War es hilfreich?

Lösung

Abort! Abort!

Basically I totally misunderstood what the badge is and how to use it. What I was trying to do is to detect click on image and call the badge. This is fundamentally wrong since all I needed to do was to simply use QuickContactBadge INSTEAD of ImageView in my code. After I replaced images with badges in the item XML magic was automatically there.

Said that - it is possible to pop the badge using the code, refer to this article on how to do it

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top