setText () does not change the text in textView Fragments Android

0

I have a fragment that receives an object and from it it fills some textView, but in my case it leaves empty textViews. I have already verified that the object is created correctly and returns information through a Log. These are the onCrate and onCreateView methods, which are the methods where I have code in the fragment:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getArguments() != null){
            Alumno alum = (Alumno) getArguments().getSerializable("User");
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_perfil, container, false);
        miTextViewPerfilDNI = (TextView) view.findViewById(R.id.textViewPerfilDNI);
        miTextViewPerfilNombre = (TextView) view.findViewById(R.id.textViewPerfilNombre);
        miTextViewPerfilApell = (TextView) view.findViewById(R.id.textViewPerfilApell);
        miTextViewPerfilNacim = (TextView) view.findViewById(R.id.textViewPerfilNacim);
        miTextViewPerfilArea = (TextView) view.findViewById(R.id.textViewPerfilNacim);
        miTextViewCursoCoordinadorUp = (TextView) view.findViewById(R.id.textPerfilCursoCoordinadorUp);
        miTextViewPerfilCursoCoordinador = (TextView) view.findViewById(R.id.textViewPerfilCursoCoordinador);
        miTextViewPerfilClave = (TextView) view.findViewById(R.id.textViewPerfilClave);
        miEditPerfilDato1 = (EditText) view.findViewById(R.id.editPerfilDato1);
        miEditPerfilDato2 = (EditText) view.findViewById(R.id.editPerfilDato2);
        miEditPerfilDato3 = (EditText) view.findViewById(R.id.editPerfilDato3);
        miEditPerfilHobbie1 = (EditText) view.findViewById(R.id.editPerfilHobbie1);
        miEditPerfilHobbie2 = (EditText) view.findViewById(R.id.editPerfilHobbie2);
        miEditPerfilHobbie3 = (EditText) view.findViewById(R.id.editPerfilHobbie3);
        miBotonGuardar = (Button) view.findViewById(R.id.botonGuardarPerfil);

        // Se rellenan los campos
        miTextViewPerfilDNI.setText(alum.getNombre());
        miTextViewPerfilNombre.setText(alum.getNombre());
        miTextViewPerfilApell.setText(alum.getApellidos());
        miTextViewPerfilNacim.setText(alum.getF_nacim().toString());
        miTextViewPerfilArea.setText(alum.getArea());
        miTextViewPerfilCursoCoordinador.setText(String.valueOf(alum.getCurso()));
        miTextViewPerfilClave.setText(alum.getClave());
        miEditPerfilDato1.setText(alum.getDatos_interesantes().getDato1());
        miEditPerfilDato2.setText(alum.getDatos_interesantes().getDato2());
        miEditPerfilDato3.setText(alum.getDatos_interesantes().getDato3());
        miEditPerfilHobbie1.setText(alum.getHobbies().getHobbie1());
        miEditPerfilHobbie2.setText(alum.getHobbies().getHobbie2());
        miEditPerfilHobbie3.setText(alum.getHobbies().getHobbie3());

        return inflater.inflate(R.layout.fragment_perfil, container, false);
    }

If more information is needed, please tell me.

    
asked by PacoPepe 12.05.2018 в 16:25
source

1 answer

1

The problem is that you are inflating a view nueva of zero, instead of returning the one created in the return of onCreateView .

In your case, just return view where the modified reference is stored. If that is not the case, assuming that it does not give you errors in runtime and you say that the "data exists". Then check if in your layout, the color of the text is equal to your background , usually happens.

As @DavidMinaya says in the comment, similarly your object is being declared locally when you get Bundle . You must declare alum as a variable of the class and remove the type behind the name in onCreate .

RECOMMENDATION: To achieve better performance when passing an object through a bundle, I recommend you implement it parcelable in your object, instead of serializing it.

You can see an explanation of: Parcelable vs Serializable

    
answered by 12.05.2018 / 18:33
source