I have a button in an activity (MainActivity) and I was wondering how to set an OnClick Listener for that in a fragment. I have tried interfaces and bundles but to no avail. Any help would be greatly appreciated!
I have a button in an activity (MainActivity) and I was wondering how to set an OnClick Listener for that in a fragment. I have tried interfaces and bundles but to no avail. Any help would be greatly appreciated!
You are trying to activity button click perform from a Fragment class
try this
((MainActivity) requireContext()).button.performClick();
MainActivity is your fragment's add activity and this button access modifier sets public to access in fragment