How to resolve Error with onClick in NavigationView headerLayout Android
I have already try call clickevent with id but the same problem.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.vbagetech.taxmunshi.gstbillingapp, PID: 14363
java.lang.IllegalStateException: Could not find method editprofile(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatImageButton with id 'edit_profile_ID'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:4467)
at android.view.View$PerformClick.run(View.java:18776)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
- 6 years ago
You can't use them Views without Inflating Main View use below code for this. It is working fine for me.
View headerView = navigationView.inflateHeaderView(R.layout.nav_header_dashboard); ImageButton edit_profile=(ImageButton)headerView.findViewById(R.id.edit_profile_ID); edit_profile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getBaseContext(),EditProfileActivity.class)); } });
Hot Questions