我有一个应用程序,它使用QuickContactBadges来显示联系人照片和弹出操作窗格。
在我的布局中,在TextView下面还有一个QuickContactBadge,它显示联系人的名称。
现在,只有在单击/触摸联系人的照片( QuickContactBadge本身)时才会得到实际的快速操作窗格。当您单击显示名称的TextView时,我希望它也显示操作窗格。
是否有办法捕捉TextView的click事件并使用它触发QuickContactBadge的单击,从而显示操作窗格?
我不确定它是否真的适用于这个问题,但这是用于我的布局的XML。
<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>发布于 2012-06-02 05:21:52
在绑定TextView时,我执行了以下操作:
TextView tv = (TextView) v.findViewById(R.id.ContactName);
tv.setText(cnm);
tv.setOnClickListener(this);然后我的活动实现了OnClickListener。然后在OnClick重写中,执行以下操作:
@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;
}
}这里的关键是一行:qb.performClick();。
https://stackoverflow.com/questions/10859635
复制相似问题