'Set an on click listener on button in a fragment in the main activity file

I have tried to do some research on the topic and I am attempting to add an on-click listener for a button in a fragment in the main activity. So when I click a button in a fragment the click can get registered in the main activity file.



Solution 1:[1]

You can use custom broadcast receiver You will register a receiver on button click in fragment Then in activity apply action if this broadcast action equal to this custom action

Solution 2:[2]

you can use interface for this problem

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stud 20178034
Solution 2 hossein