0
I wonder how I can calculate with only one button two different sums, as I did the example in the image.
I have the code this way, but only with 2 numbers. How do I make another calculation simultaneously with the same button?
public void calcular (View v){
NumberFormat formatter = new DecimalFormat("#0.00");
EditText resultado1 = (EditText) findViewById(R.id.editText15);
String stringresultado1 = resultado1.getText().toString();
EditText resultado2 = (EditText) findViewById(R.id.editText19);
String stringresultado2 = resultado2.getText().toString();
double valorresultado1, valorresultado2;
if(stringresultado1.trim().isEmpty()){valorresultado1 = 0; }
else{valorresultado1 = Double.parseDouble(stringresultado1);}
if(stringresultado2.trim().isEmpty()){valorresultado2 = 0; }
else{valorresultado2 = Double.parseDouble(stringresultado2);}
if (stringresultado1.trim().isEmpty() &&stringresultado2.trim().isEmpty())
{
Toast.makeText(getApplicationContext(), "Campos em branco",
Toast.LENGTH_LONG).show();
}
else
{
double resu = valorresultado1 + valorresultado2;
TextView resultado = (TextView) findViewById(R.id.textView32);
resultado.setText (formatter.format(resu) + "€" );
}
}
@Wéllingthonm.Souza reversed its edition because, despite improving some points of the question, changed a linguistic character of the user, who is probably from Portugal. I recommend reading https://pt.meta.stackoverflow.com/q/3/28595
– user28595
@Articuno, no problem, thanks for the tip :).
– NoobSaibot
What are the
EditText
andTextView
of every thing on the screen ? Probably the xml layout will make it clearer– Isac
Edittext: A and B. Textview: Result. I have the above code, maybe it helps. Here my doubt is for the same button to calculate simultaneously.
– S0nkit3
@Article In European Portuguese "Liked" remains imperfect past tense in the same way as here in Brazil and having the same denotative sense. The correct form in the two dialects would be "Would like" even in the future of the past.
– Victor Stafusa