0
I have a class to apply the monetary mask, I apply this class in editText Library.
This being a field for discount I need him to do two things 1 - show the value formatted in our currency ex R$ 21.36 (this is OK) 2 - I need to call a method to calculate the total that is nothing more than the value (unitario * quantity) - discount
it is possible to have more than one Istener?
edtDesconto.addTextChangedListener(new MaskMonetaria(edtDesconto));
We will use the class Maskmonetaria that is doing its role correctly, and we will use the loss of Focus or when the user leaves the field discount the calculation of the total will be called this way we have what we want and it works! yes, everything works more has a however, which is the reason of my question
like this day
edtDesconto.addTextChangedListener(
new MaskMonetaria(edtDesconto)
);
edtTotal.addTextChangedListener(
new MaskMonetaria(edtTotal)
);
edtDesconto.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
EditText et = (EditText)v;
if (hasFocus){
// Fazer Nada
Log.i(TAG, "onFocusChange" + "Tem Foco");
} else {
Log.i(TAG, "onFocusChange" + "Sem Foco");
calculaTotais();
}
}
});
now the fields on the screen
- Produto
- valor unitário(desabilitado)
- quantidade
- desconto
- total(desabilitado)
- Botão Gravar
We realize here that there is no change of focus between Discount and the Record button because among them Total is disabled, the action of recording the data ends the activity so that the user does not even see the Total Value
As I can not in the listener have the formatting class and the method that calculates the totals at the same time I came looking for some answer because I believe that my intention should be very common.
The idea of a method called
addListener
is to indicate to the programmer that the passed Listener will be placed in parallel to the others; this differs from a method calledsetListener
, that passes the idea that there can only be one. Now, of course, to be sure it is necessary to read the documentation. In the case of the Android API, theaddListener
has the expected behavior. I don’t know if it’s my paranoia, but I would put all these features in the call of the same Switch, which would delegate to the handlers (mask applicator/price calculator) their needs– Jefferson Quesado
Hello Jefferson good afternoon, I improved my question giving more details, more I wonder if your suggestion I understood correctly, your suggestion would be I transform the class that gives the monetary mask as a class or method internal to the listener of the field ex edtDesconto.addTextChangedListener(new Textwatcher() and in this do the mask and call the method of adding?
– Robson