Hello, Victor. I'll write a very quick code here to try to help you. This data transfer between Fragments will always have Activity as an intermediary. The Fragment that received the click will pass the element to the Activity and Activity will transfer the element to the second Fragment.
So, to begin with, the idea is that your Activity implements an interface that the Fragment that will suffer the click knows and calls. So let's create the interface that will be called when there was a click on the fragment:
public interface OnPesquisarClickListener {
public void onPesquisarClick(MeuObjeto meuObjeto);
}
Then let's make Activity inherit from this interface and implement the method:
public class MinhaActivity extends AppCompact implements OnPesquisarClickListener {
//... Outros métodos comuns da Activity
public void onPesquisarClick(MeuObjeto meuObjeto) {
//Transfira o objeto para o fragmento dois aqui. Por exemplo, fragmentoDois.pesquisar(meuObjeto)...
}
}
Okay, now in your clickable fragment, during the onAttach()
method, which is called during the fragment lifecycle when a fragment is appended to Activity, capture the Activity using polymorphism for terms in one hand instance of OnPesquisarClickListener. This way:
public void FragmentTwo extends Fragment {
OnPesquisarClickListener onPesquisarClickListener
@Override
public void onAttach(Context context) {
if(context instanceof OnPesquisarClickListener) {
onPesquisarClickListener = (OnPesquisarClickListener) context;
}
super.onAttach(context);
}
//Métodos comuns ao fragment
}
And in that method you described will call the instance of OnPesquisarClickListener that we received:
holder.search = (ImageView) view.findViewById(R.id.iv_search);
holder.search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//onPesquisarClickListener.onPesquisarClick(...
}
});
Any questions just say that I try to explain in other ways. Abs!