Invoke Fragment within Fragment

0

I'm developing a chat. I have a MainActivity in which I invoke a fragment (which extends baseAdapter), where all contacts in a listview are ready. When I click on a contact, I want to open a new fragment that represents the send / receive window of the sms.

My problem is to invoke the second fragment (inside the onClickListener), is it possible / correct to invoke a fragment already inside a fragment? if so, how can I circumvent this situation?

    
asked by anonymous 26.04.2017 / 13:18

1 answer

0

An example of how to solve this situation, taking into account that as Ramaral said in the comment, the activity is responsible for changing the fragment there:

//Instancia o fragmentManager que é o responsável pela troca de Fragment
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
//Instancia o fragment que você vai colocar na tela
Fragment fragment = new SeuFragment();
//Faz a transação, substituindo no frame da sua MainActivity que contem os fragmentos, o antigo pelo novo fragmento que você instanciou.
fragmentManager.beginTransaction().replace(R.id.main_framelayout, fragment).commit();

Basically this is a very simple and generic way to change the screen from a Fragment, remember that if you want to pass some information forward, just instantiate a bundle and arrow it in the instantiated fragment:)

    
26.04.2017 / 15:04