• Jueves 18 de Abril de 2024, 21:48

Autor Tema:  Comunicacion entre fragments (problema)  (Leído 2138 veces)

kempacc

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Comunicacion entre fragments (problema)
« en: Viernes 26 de Mayo de 2017, 21:54 »
0
Muy buenas tardes gente, pido ayuda en un problema que tengo, resumo mi problema.
Estava haciendo una prueba entre dos fragments, donde paso un simple texto para mostrarse en el segundo fragment pero me sale el siguiente error.
java.lang.NullPointerException

En la siguiente linea
Código: [Seleccionar]
   fragment =getFragmentManager();
            f2 = (SecondView) fragment.findFragmentById(R.id.fragment2);
            f2.updateInfo(name);
            replace();

Y aqui muestro el fragment donde quiero enviar el texto.
Código: [Seleccionar]
Código: [Seleccionar]


public class SecondView extends Fragment {

    TextView mostrar;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.second_fragment,container,false);

        mostrar = (TextView)getActivity().findViewById(R.id.Mostrar);






        return view;
    }


    public void updateInfo(String name){

        mostrar.setText(name);
}

}

Eh intentando varias formas para resolver el problema pero nada a funcionaba alguien me puede ayudar?