-4

I've created a navigation drawer using a navigation drawer activity. All I am trying to do is setonClicklistener on the Fab. But, it is not responding. I've tried to change it to Imageview & CircleImageView.

The java code for onclicklistener is below

 profnewfab = (FloatingActionButton) findViewById(R.id.profile_new); 
        if (profnewfab != null) {
            profnewfab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
                    startActivityForResult(galleryIntent, RESULT_LOAD_IMG);


                }
            });
        }

The Following is the code of my nav_header_profile.xml.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="@dimen/nav_header_height"
        android:background="@drawable/navheaderbg"
        android:gravity="bottom"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:theme="@style/ThemeOverlay.AppCompat.Dark"
        android:weightSum="1">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/profile_new"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            app:backgroundTint="#37474F"
            android:src="@drawable/usericon_new" />

        <android.support.v7.widget.CardView
            android:alpha="0.8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <TextView
            android:layout_marginTop="8dp"
            android:id="@+id/susernametv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:textAppearance="?android:attr/textAppearanceMedium" />

    </android.support.v7.widget.CardView>
    </LinearLayout>
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Possible duplicate of [Android: OnClick for navigation drawer header not working](http://stackoverflow.com/questions/31716034/android-onclick-for-navigation-drawer-header-not-working) – Mike M. Jul 01 '16 at 07:10

1 Answers1

0

try this

 NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View header = navigationView.getHeaderView(0);
    FloatingActionButton FloatingActionButton= (FloatingActionButton) header.findViewById(R.id.loatingActionButton);
FloatingActionButton.setOnclickListener(.....)
Mohit Madaan
  • 469
  • 2
  • 11