Answer the question
In order to leave comments, you need to log in
How to call a method from MainActivity when clicking on ReryclerView element?
I did it like this, but it doesn’t work, I don’t understand how to use point 4, what needs to be passed to the constructor from the adapter so that it doesn’t equal null?
public interface OnRecyclerViewItemClickListener {
void onClick();
}
public class MainActivity extends AppCompatActivity implements OnRecyclerViewItemClickListener {
...
@Override
public void onClick() {
}
}
private OnRecyclerViewItemClickListener mClickListener;
public MyAwesomeAdapter(OnRecyclerViewItemClickListener clickListener) {
mClickListener = clickListener;
}
if (mClickListener != null) {
mClickListener.onClick();
}
Answer the question
In order to leave comments, you need to log in
In this option, when creating an adapter in an activity, you need to pass this to the constructor.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question