0

I have a standard navigation drawer. It's a ListView:

        <ListView android:id="@+id/fragmentLeftDrawer"
            android:layout_width="304dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:textStyle="bold"
            android:dividerHeight="0dp"/>

populated by drawer_list_item.xml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:padding="10dp">

    <ImageView
        android:id="@+id/navDrawerImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_centerVertical="true"
        android:paddingStart="16dp"
        android:paddingEnd="16dp"/>

    <TextView
        android:id="@+id/navDrawerTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toEndOf="@+id/navDrawerImageView"
        android:paddingStart="16dp"
        android:paddingEnd="16dp"/>

</RelativeLayout>

This works fine. Now, I want to replace the ImageView with something like this Github project. It is essentially a custom class which extends ImageView. (My class is very similar to the linked project, so for the purposes of this question, just assume they're identical.)

If I replace the ImageView in drawer_list_item.xml with something like this:

<package.appname.CustomClass
    android:id="@+id/navDrawerCustomImageView"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_centerVertical="true"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"/>

then, the navigation drawer will not respond to click events. It will only open and close but not navigate to different parts of the apps. No errors or crashes occur.

Does anyone know why this happens? Please let me know. Any advice is appreciated.

Edit: I should mention that I've also tried toggling android:clickable on my custom ImageView to see if it had any effect, but no differences arose.

pez
  • 3,859
  • 12
  • 40
  • 72
  • Maybe your `CustomClass` overrides touch logic(onClickListener, onTouchListener). – dreambit.io dreambitio Jun 20 '15 at 21:30
  • Please show how you set `onClickListener` – dreambit.io dreambitio Jun 20 '15 at 21:31
  • @EldarMensutov You can see all the logic for my custom class [here](https://github.com/markushi/android-circlebutton/blob/master/library/src/main/java/at/markushi/ui/CircleButton.java). It behaves very similarly to this project, except for cosmetic changes which are irrelevant to the current problem. It just overrides `setPressed()`. For the `ListView`, in my main activity I call `mDrawerList.setOnItemClickListener(...)`. – pez Jun 20 '15 at 21:34

1 Answers1

0

Okay, I seem to understand. Yours custom view calls inside self setClickable(true) Remove it.

The shortest explanation here

Community
  • 1
  • 1
dreambit.io dreambitio
  • 1,892
  • 1
  • 15
  • 24
  • I had previously set `android:clickable="false"` in the `xml`, but saw no improvement. Just to be sure, I just defined a new `styleable` `boolean` attribute, in the `xml` I set `app:customview_clickable="false"`, then called `setClickable(isClickable)` in the custom view code. But it still doesn't work. Thanks for the idea, though. – pez Jun 20 '15 at 22:08