Error summing Edit Text fields using Onfocuschangelistener

Asked

Viewed 93 times

1

I’m trying to get my application to calculate the fields EditText cost price plus profit percentage and when clicking on the sales price field the result already appears, but instead of appearing the result appears the following message in the Edit text of the field:

android.widget.Edittext@41f

Thanks to anyone who can help in the most specific way possible because I have no experience.

  OnFocusChangeListener focusListener = new View.OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {

                custo = MonetaryMask.stringMonetarioToDouble(edPrecoDeCusto.getText().toString());
                lucro = MonetaryMask.stringMonetarioToDouble(edPercDeLucro.getText().toString());
                venda = MonetaryMask.stringMonetarioToDouble(edPrecoDeVenda.getText().toString());

                venda = calcularLucro(custo, lucro);
                edPrecoDeVenda.setText(edPrecoDeVenda.toString());

            }

        }
    };


   edPercDeLucro.setOnFocusChangeListener(focusListener);      


    private double calcularLucro(double custo, double lucro) {
             venda = custo + lucro / 100 * custo;
      return venda;
}

1 answer

1


You are going to String with the memory reference of the object:

edPrecoDeVenda.toString()

Try it this way:

 edPrecoDeVenda.setText(venda);

With the getText(), you will take the value of the field !

  • I did as you suggested but he is not performing the calculation. Is not giving the error but also does not perform the calculation, any suggestion ? @Thiago Luiz Domacoski

  • try like this: edPrecoDeVenda.setText(sale); For you arrow the calculation in this variable, right?

  • I edited the answer too !

  • Thank you !! 100% @ Thiago Luiz Domacoski

Browser other questions tagged

You are not signed in. Login or sign up in order to post.