0
I’m trying to instantiate a method that returns a value of type int in a fragment, but when I show the value on the device screen Textview shows this: null.
Fragment code:
public View onCreateView(/*@NonNull*/ LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
Valor valor = new Valor();
// TXTVIDAS
TextView vidas = view.findViewById(R.id.txtVidas);
vidas.setText(String.valueOf("fgdfhgd" + valor.getVidas()));
// Botão começar
Button btncomecar = (Button) view.findViewById(R.id.btncomecar);
btncomecar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), MundosActivity.class);
startActivity(intent);
}
});
return view;
I tested and the method returns a value other than null:
D/Vidas encotradas: 4
I mean, there should be a four instead of "null".
I can solve the problem otherwise, but thanks for the help!
– João Paulo