Frage

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>
War es hilfreich?

Lösung

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();.

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