Choose which fragment will be shown in the activity

0

I have Activity that the email is requested and if the email exists it shows a Activity with a Fragment to enter the password. If this email does not exist, I want to display a Fragment , in the same Activity , for a registration to be made.

My question is: How to choose which Fragment will be inflated? How can I do this?

    
asked by anonymous 13.09.2016 / 21:34

2 answers

2

You can receive a boolean parameter in activity # 2, for example "temCadastro". Make an if in activity # 2

    if(temCadastro == true) {
      digitarSenha();
    } else { mostraCadastro();
    } 

Within the typedEnter () method and the Cadaster () show you inflate the fragment, not the xml layout of the fragment. Home The logical test if you register is done in activity # 2 (the xml of this activity will be "blank"). The activity decides which fragment to launch based on the logical test temCadastro..The fragment will "sprout" on top of the activity (the fragment is made up of a specific class of fragment + xml). The interesting thing to note is that the fragment is different from a pop-up, known as dialog.

    
14.09.2016 / 22:26
2

First you need to create a condition to check your issues

  

If this email does not exist, I want to display a fragment.

Try to create a method that returns a boolean with the name for example emailExiste () Then you do this:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if(emailExiste){        
    transaction.replace(R.id.fragment_container, fragmentEmailExiste);      
} else {        
    transaction.replace(R.id.fragment_container, fragmentEmailNaoExiste);  
}    
transaction.addToBackStack(null);
transaction.commit(); 
    
13.09.2016 / 23:05