Home > Mobile >  Android studio : Could not find method XXXXX(View) in a parent or ancestor Context for android:onCli
Android studio : Could not find method XXXXX(View) in a parent or ancestor Context for android:onCli

Time:02-11

I have this error when I try to use a button with an android:onClick from a fragment :

enter image description here

fragment.java : enter image description here fragment.xml :

enter image description here

But in the design tool, it is well recognized :

enter image description here

I am aware that the issue is probably somewhere else in the code but I really dont know what to check ?

CodePudding user response:

With certitude, the called method by the onclick must be on the activity.java which launches the fragment.java even if you are in this fragment. But in this case in the design tool, in the onclick field, your method does not appear. You need to add and define android:onClick manually. It remains a bit unclear but it works fine even if I probably do not use the right method.

  • Related