无法捕获自定义android视图上的单击事件

时间:2014-03-13 15:05:27

标签: java android android-layout layout

我有这个xml:

<com.me.view.button.SwipeableButton
        android:id="@+id/mainMenuSwipeableButton"
        android:layout_width="250dp"
        android:layout_height="62dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="2dp"
        android:layout_marginLeft="2dp"
        app:button="@drawable/main_menu_button"
        android:visibility="visible" />

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/icon_menu_press" /> <!-- pressed -->
    <item android:drawable="@drawable/icon_menu" /> <!-- default -->
</selector>

当我有这个代码时,为什么我的点击不被抓住?

 setCloseToolTipClickListener(getMainLayout().findViewById(R.id.mainMenuSwipeableButton),  tooltipView);

  private void setCloseToolTipClickListener(View view, final LinearLayout tooltip) {
    view.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        tooltip.setVisibility(View.GONE);
      }
    });
  }

0 个答案:

没有答案