I have a FragmentActivity where I add a Fragment.
Depending on some situation, I want to access Buttons from that fragment\'s layout
To set OnClickListeners in fragments, override onViewCreated in your fragment class.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.yourId).setOnClickListener(this);
//or
getActivity().findViewById(R.id.yourId).setOnClickListener(this);
}
I was trying to set a timertask to automatically reload a webview in a fragment and this method was the only thing that worked for me. My project is on github.
Source: this answer