I have an Activity and two Fragments. The first one is a list of items and the second one is detailed view. Ideally I would like to send String id from Fragment 1 to Fragment 2 (when item is clicked) in order to perform new detail query to the API. However, right now I am so confused I just want to understand where do I set the clicklistener. I've tried in:
Fragment 1's onCreateView:
recyclerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(activity,"Hello", Toast.LENGTH_SHORT).show();
Log.v("Fragment1", "CLICK !? CLICK !? CLICK !? ");
}
});
Fragment 1's Adapter - onBindViewHolder
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context,"Hello", Toast.LENGTH_SHORT).show();
Log.v("Adapter", "CLICK !? CLICK !? CLICK !? ");
}
});
My activity_main.xml is just a FrameLayout and I have separate xml with just RecyclerView, and template xml's for each fragment
RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
I have those in my fragment 1's linearlayout (not sure if relevant)
android:clickable="true"
android:focusable="true"
Thank you!