I have an ImageButton I can access in my Activity and in my Fragment. I want actions to be done in both of those said classes so I implemented an onClickListener for both of them.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
ImageButton imageButton = (ImageButton) findViewById(R.id.my_image_button);
imageButton.setOnClickListener(new OnClickListener() ...);
}
And the same simple piece of code for the fragment launched by this activity (But in onViewCreated).
I tried it and only the Fragment's onClickListener is triggered.
So, here is my question, is there a way to make my button trigger both Activity's and Fragment's onClickListener ?
I know I could call a Fragment's method from the Activity's onClick, but it would be so much simpler to just trigger it inside the Fragment aswell.
EDIT :
I am not willing to do this through two OnClickListener at any cost, it was just in case there were a simpler way than Activity to Fragment callbacks (in my case).
As 空気嫁 said, a second onClickListener would disable the first one. In that case, only callbacks left.
Plus, after thinking a bit about it, it would make the code easier to understand too. Callbacks, yeah !