1

I have an app which uses QuickContactBadges to show contact photos and the popup action pane.

In my layout, I also have a TextView beneath the QuickContactBadge which displays the contact's name.

Right now you only get the actual quick action pane when you click/touch on the contact's photo (the QuickContactBadge proper). I'd LIKE for it to also show the action pane when you click on the TextView showing the name.

Is there some way to catch the TextView's click event and use it to trigger the QuickContactBadge's click, thereby showing the action pane?

I'm not sure it's really applicable for the question, but here is the XML for my layout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top|center_horizontal"
    android:orientation="vertical" >

    <QuickContactBadge
        android:id="@+id/ContactBadge"
        android:layout_width="48dp"
        android:layout_height="48dp" >
    </QuickContactBadge>

    <TextView
        android:id="@+id/ContactName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:ellipsize="end"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:freezesText="true"
        android:gravity="top|center_horizontal"
        android:lines="2"
        android:text="@string/val_DefaultString" >
    </TextView>

</LinearLayout>
eidylon
  • 7,068
  • 20
  • 75
  • 118
  • Check out the answers to [this question](http://stackoverflow.com/questions/5162374/implementing-code-behind-clickable-textviews). – Rob I Jun 02 '12 at 03:56
  • 1
    That is half of the problem. That does not click the `QuickContactBadge` though. If, in the `TextView` `onClickListener` I call the `QCB`'s `performClick() method, will this show the action pane? It sounds like it should from the documentation, no? – eidylon Jun 02 '12 at 04:05
  • 1
    Ah, cool. Yes, `performClick()` does show the `QuickContactBadge`'s action pane. That completes it. – eidylon Jun 02 '12 at 04:39

1 Answers1

2

When binding the TextView, I did the following:

TextView tv = (TextView) v.findViewById(R.id.ContactName);
tv.setText(cnm);
tv.setOnClickListener(this);

My activity then implements OnClickListener. Then in the OnClick overrides, do the following:

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.ContactName:
            TextView tv = (TextView) v;
            LinearLayout ll = (LinearLayout) tv.getParent();
            QuickContactBadge qb = (QuickContactBadge) ll.findViewById(R.id.ContactBadge);
            qb.performClick();

            break;
    }
}

The key here is the line: qb.performClick();.

eidylon
  • 7,068
  • 20
  • 75
  • 118