[Solved] Calculating percentages value of edittext in android


Suppose service_tax_et and penalty_et are new editTexts, don’t add them to the array instead set focusChangeListener on them manually and then try like this:

private View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
    float total = 0;
    for (int i=0 ; i<editTexts.length-1 ; i++) {
        try {
            total += Integer.valueOf(editTexts[i].getText().toString());
        }
        catch(Exception e) {}
    }

    try {
        float service_tax_perc = (Integer.valueOf(monthly_rent_et.getText().toString()) + Integer.valueOf(service_tax_et.getText().toString())) / 100;
        total += service_tax_perc;
    } catch (Exception e) {}

    try {
        float penalty_perc = (Integer.valueOf(monthly_rent_et.getText().toString()) + Integer.valueOf(penalty_et.getText().toString())) / 100;
        total += penalty_perc;
    } catch (Exception e) {}

    total_et.setText(total + "");
}};

0

solved Calculating percentages value of edittext in android