Skip to content Skip to sidebar Skip to footer

Button Click In Android Fragment Does Not Work

activity_main.xml

Solution 1:

The way XML onClick is implemented is directed to Activities, not Fragments. The activity should own the btnClick1 method, not a fragment.

Solution 2:

You need to assign OnClickListener in fragment code to make it work. See Snicolas answer for the "why".

Solution 3:

Since others have addressed setting onClick listener, let me add that if you have done so, and still getting the error check permissions required. For my case, the item on fragment was meant to open chat which requires microphone so it was not working until I added appropriate permissions in Manifest file.

Post a Comment for "Button Click In Android Fragment Does Not Work"