0
Hello,
I need to pass the parameters of two screens to the tela_inicio, be the "BALANCE" parameters of the screen balance where it will be passed to an Edittext (lblSaldoAtual) at tela_inicio and then pick up a value put in "EXTRA" on the screen addirsald and add to the "BALANCE" parameter and display in lblSaldoAtual on the screen tela_inicio
Help please Thank you.
START SCREEN
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tela_inicio);
lblSaldoAtual = (TextView) findViewById(R.id.lblSaldoAtual);
btnSaldo = (Button) findViewById(R.id.btnSaldo);
lblSaldoTotal = (TextView) findViewById(R.id.lblSaldoTotal);
btnMenos = (ImageView) findViewById(R.id.btnMenos);
bMais = (Button) findViewById(R.id.bMais);
bMenos = (Button) findViewById(R.id.bMenos);
btnSaldo.setOnClickListener(this);
btnMenos.setOnClickListener(this);
bMais.setOnClickListener(this);
bMenos.setOnClickListener(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Classe1 classe = new Classe1();
classe.recebesaldo();
classe.recebeextra();
}
class Classe1 {
Double extra, saldoatual, saldototal, total;
public void recebesaldo() {
Intent it = getIntent();
if (it != null) {
Bundle b1 = it.getExtras();
saldoatual = Double.parseDouble(b1.getString("SALDO"));
lblSaldoAtual.setText(Double.toString(saldoatual));
saldototal = Double.parseDouble(b1.getString("SALDO"));
lblSaldoTotal.setText(Double.toString(saldototal));
}
}
public void recebeextra() {
Intent it2 = getIntent();
extra = Double.parseDouble(it2.getStringExtra("EXTRA"));
total = extra + saldoatual;
lblSaldoAtual.setText(Double.toString(total));
}
}
public void onClick(View view) {
if (view == btnSaldo) {
Intent it = new Intent(this, saldo.class);
startActivity(it);}
else if (view == bMais) {
Intent it = new Intent(this, acrescentarsaldo.class);
startActivity(it);
} else if (view == bMenos) {
Intent it = new Intent(this, acrescentarsaldo.class);
startActivity(it);
}
}
SPLASH SCREEN
public class acrescentarsaldo extends AppCompatActivity implements View.OnClickListener{
private Button btnOK;
private EditText txtAcrescentarSaldo;
public static String acrescenta;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_acrescentarsaldo);
btnOK = (Button) findViewById(R.id.btnOK);
txtAcrescentarSaldo = (EditText) findViewById(R.id.txtAcrescentarSaldo);
btnOK.setOnClickListener(acrescentarsaldo.this);
}
public static String getAcrescenta(){
return acrescenta;
}
public void onClick(View v) {
Intent it = new Intent(acrescentarsaldo.this, tela_inicio.class);
it.putExtra("EXTRA", txtAcrescentarSaldo.getText().toString());
startActivity(it);
}
}
SCREEN BALANCE
public class saldo extends AppCompatActivity implements View.OnClickListener{
private EditText txtAtualizar;
private Button btnAtualizar;
private static String saldo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_saldo);
btnAtualizar = (Button) findViewById(R.id.btnAtualizar);
txtAtualizar = (EditText) findViewById(R.id.txtAtualizar);
btnAtualizar.setOnClickListener(saldo.this);
}
public static String getSaldo(){
return saldo;
}
@Override
public void onClick(View view) {
Intent it = new Intent(saldo.this, tela_inicio.class);
it.putExtra("SALDO", txtAtualizar.getText().toString());
startActivity(it);
}
}
See if it’s this what you seek.
– ramaral
No, I couldn’t use it this way
– Gabriel
You’ll have to explain better because it’s not clear what you want.
– ramaral
I edited the question, I hope I was clearer
– Gabriel