Pass data between fragments and Activitys with radio button

Asked

Viewed 95 times

0

I’m having trouble passing data from an Activity to a Fragment, I would like to use a radio button to define a parameter for a variable, dps pass this value so the Fragment can do the treatment, example... When logging in the user would choose the Adm option and this parameter would be sent to the Fragment that is inside an if to determine the chosen option. How to pass this data ???

The structure would look something like this...

Checking the type in Activity

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

In the Fragment

Here I would have to receive this variable type there from Activity with the values and start processing 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");

    }

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");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.