Q:

referencing a textview in a fragment gives a null value

i have 2 xml files, one containing a recyclerview(main_fragment.xml) and another containing the items to render on that recyclerview(main_item.xml). my fragment(MainFragment.java) extends Fragment. main_item contains a textview.  In MainFragment.java i am inflating main_fragment.xml. Now i want to reference the textview in main_item.xml so as to listen for a click. but i get a null  pointer. I get that is because in MainFragment.java i am inflating main_fragment.xml and not main_item.xml. Pls where should should i setup the onClickListener for the textview in main_item.xml. Thanks

A:

This needs to be done in you RecyclerView.Adapter and more specifically in the ViewHolder of the adapter. 
There are many post on SO about that. 
RecyclerView onClick

