Pass data between fragments and Activitys with radio button

0

I'm having trouble passing data from an activity to a fragment, I'd like to use a radio button to set a parameter for a variable, dps pass that value to the fragment to be able to do the treatment, example ... At the time of login the user would choose the adm option and this parameter would be sent to the fragment that inside an if to determine the chosen option. How to pass this data ???

The structure would look something like this ...

Checking the type in the activity

if (morador.isChecked()){
                tipo = "morador";
            }
            if (sindico.isChecked()){
                tipo = "sindico";
            }

No fragment

Here I would have to receive this type variable there from the activity with the values and proceed to treat the data ...

    //Caminho

    if(tipo == sindico) {

        databaseReference1 = FirebaseConfig.getFirebase().child("Usuarios").child(usuarioLogado).child("nome");
        databaseReference2 = FirebaseConfig.getFirebase().child("Usuarios").child(usuarioLogado).child("apartamento");
        databaseReference3 = FirebaseConfig.getFirebase().child("Usuarios").child(usuarioLogado).child("bloco");

   }else if(tipo == morador) {
         databaseReference1 = FirebaseConfig.getFirebase().child("Sindico").child(usuarioLogado).child("nome");
        databaseReference2 = FirebaseConfig.getFirebase().child("Sindico").child(usuarioLogado).child("apartamento");
        databaseReference3 = FirebaseConfig.getFirebase().child("Sindico").child(usuarioLogado).child("bloco");

    }
    
asked by anonymous 12.06.2017 / 21:06

1 answer

1

Before Calling your Fragment puts this:

Bundle args = new Bundle();
args.putString("VarTpUsuario", VarTpUsuario);
frag.setArguments(args);

In Fragment, try this:

Intent myIntent = getIntent();
VarTpUsuario = myIntent.getString("VarTpUsuario");
    
12.06.2017 / 21:44