Home > front end >  Could not find method "method" in a parent or ancestor Context for android:onClick attribu
Could not find method "method" in a parent or ancestor Context for android:onClick attribu

Time:08-29

I am trying to get this button to launch a block of code but it can't seem to find it. This is a button in a fragment that is trying to launch another fragment inside a single activity architecture.

Method that gets called (Notice how it's greyed out)

Button that calls the method

Android complaining that this doesn't exist yet

Design properties seeing function just fine

Error that I get

What exactly am I doing wrong here?

CodePudding user response:

The answer to my problem was to just set up the calls programmatically vs in layout for fragments. Using a setOnClickListener with the binding in onCreateView worked. If you are using a binding, make sure to return binding.root in the onCreateView, or else it won't work.

  • Related