Best Approach To Communicate Between Fragment/activity And Recyclerview.adapter?
My fragment: public class FragmentSort extends Fragment { @BindView(R.id.sortRecyclerView) RecyclerView sortRecyclerView; protected RecyclerView.Adapter adapter; @Nullabl
Solution 1:
An alternative would be to create a listener interface like this:
publicinterfaceOnStoreItemClickListener {
publicvoidonStoreItemClicked(Store item);
}
Then, in your Adapter, you declare a field of type OnStoreItemClickListener
and you create a setter method for it.
When you detect a click, you simply check if your listener is set and call the onStoreItemClicked()
method.
You can register a listener via the setter from wherever you need.
Post a Comment for "Best Approach To Communicate Between Fragment/activity And Recyclerview.adapter?"