[Android] I'd like to ask you how to use a click event for a view in a custom navigation view.

Asked 2 years ago, Updated 2 years ago, 22 views

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
  >

    <ImageView
        android:id="@+id/drawer_login_img"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_gravity="center"
        android:clickable="true"
        android:layout_marginTop="60dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/drawer_img"
        />

    <TextView
        android:id="@+id/drawer_login_txt"
        android:layout_below="@id/drawer_login_img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="10dp"
        android:layout_centerHorizontal="true"
        android:text="@string/drawer_txt"
        android:textColor="@color/drawerTxt"
        />


    <ListView
        android:id="@+id/drawer_list"
        android:layout_below="@id/drawer_login_txt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </ListView>

    <TextView
        android:id="@+id/drawer_setting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="12dp"
        android:gravity="center_vertical"
        android:layout_alignParentBottom="true"
        android:text="@string/drawer_text_app_setting"
        android:textColor="@color/drawerTxt">
    </TextView>

</RelativeLayout>

As above, we customize the navigation view and include it in the activity layout. What I want to implement is to click on the image view of the navigation view and move on to another activity. The getheader function fetches the image view and adds a click listener, but a null object appears. I tried many things while looking at Google, but it didn't work. I wonder if there is another way. <

android java

2022-09-21 17:44

1 Answers

I posted a question and tried it again, but it's solved. I couldn't get the getheader because I customized it. You can import it using the getRootView function!


2022-09-21 17:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.