1
I’m trying to change the value of a variable in another class but I’m not getting it.
package com.cursoandroid.firebaseapp.novotestebanco;
public class Logado {
public String situacao;
Logado(String situacao){
this.situacao = "deslogado";
}
public String getSituacao() {
return situacao;
}
public void setSituacao(String situacao) {
this.situacao = situacao;
}
}
botaoMostrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Logado logado = new Logado("");
logado.setSituacao("logado");
mostrar.setText(logado.getSituacao());
startActivity(new Intent(MainActivity.this, Mostrar.class));
}
});
Class Show
public class Mostrar extends AppCompatActivity {
public TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mostrar);
text = (TextView) findViewById(R.id.texto);
Logado logado = new Logado("");
text.setText(logado.getSituacao());
}
}
Can you give more details? Which variable do you want to change? What happens when you try to run your program? Do you have an error? It’ll make it easier for the staff to answer you.
– Lucas Cunha
Note that in the constructor
Logado(String situacao)
the situation parameter is useless since you initialize the attribute with a fixed valuethis.situacao = "deslogado"
.– mari
put the variable as Static and it worked, vlw same personal by the help.
– Davyson Diogenes