There is a custom button, from it you need to transfer your parameters to the fragment, for this I use the interface:
public interface ColorButtonClickListener{ public void onClickButton(View view); } Now, on click, I call this interface and pass it to the method context:
ColorButtonClickListener colorButton = (ColorButtonClickListener) getContext(); colorButton.onClickButton(this); At the time of the click an exception occurs:
java.lang.ClassCastException: ua.com.tarde.finish_paint.MainActivity cannot be cast to ua.com.tarde.finish_paint.Views.ColorButton$ColorButtonClickListener at ua.com.tarde.finish_paint.Views.ColorButton.onTouchEvent(ColorButton.java:106) The error gives the line where I bring the interface. There is no error when implementing the MainActivity interface. I understand that the fragment does not live separately from the activity, and the problem is somewhere in this. I just do not understand why the implementation of clicks cannot be placed in the fragment, because these buttons are there. That’s the logic of the application is built.