Error printing data in edittext

0

I'm stuck with a problem, I have to receive values in three radiogroups to do the calculation of plus 3 edittext along with the result of a method, the method works perfectly but the final calculation of all added items is not printed in edittext , wanted to know what I'm doing wrong to not pass the calculation correctly ... Here is the code:

package com.example.edfre.bleedingcalc;

import android.icu.text.NumberFormat;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
import android.content.Intent;
import android.widget.TextView;

import java.io.Serializable;


@RequiresApi(api = Build.VERSION_CODES.N)
public class BleedingMain extends AppCompatActivity {

    private RadioGroup rgGender;
    private RadioButton rbMale;
    private RadioButton rbFemale;
    private RadioGroup rgSmoker;
    private RadioButton SYes;
    private RadioButton SNo;
    private RadioGroup rgLevel;
    private RadioButton rbL1;
    private RadioButton rbL2;
    private RadioButton rbL3;
    private EditText etWeight;
    private EditText etHeight;
    private EditText etIMC;
    private EditText etHTC;
    private Button btCalculate;
    private EditText etResult;
    private double weight;
    private double height;
    private double imc;
    private double gender;
    private double smoker;
    private double level;
    private double htc;
    private double finalResult;
    private GoogleApiClient client;
    private EditText resultcalc;
    private double varResult;
    static final int CalculateBleed = 1;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client2;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client3;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client4;

    public BleedingMain() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bleeding_main);

        rgGender = (RadioGroup) findViewById(R.id.rgGender);

        rgGender.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override

            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // find which radio button is selected
                if (checkedId == R.id.rbMale) {
                    gender = 143.951;
                } else {
                    gender = 0;
                }
            }
        });
        rgSmoker = (RadioGroup) findViewById(R.id.rgSmoker);

        rgSmoker.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override

            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // find which radio button is selected
                if (checkedId == R.id.rbsYes) {
                    smoker = 274.718;
                } else {
                    smoker = 0;
                }
            }
        });
        etHeight = (EditText) findViewById(R.id.etHeight);
        etWeight = (EditText) findViewById(R.id.etWeight);
        etIMC = (EditText) findViewById(R.id.etIMC);
        etHTC = (EditText) findViewById(R.id.etHTC);
        etResult = (EditText) findViewById(R.id.etResult);


        etWeight.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //declarar variáveis
                String weightString = etWeight.getText().toString();

                // convert the String into a double
                if (weightString.length() > 0) {
                    weight = Double.parseDouble(weightString);
                }

                // read the height out of weightEdit
                String wString = etWeight.getText().toString();

                if (wString.length() > 0) {
                    weight = Double.parseDouble(weightString);
                }
                // declarar o cálculo imc
                double IMC = calcIMC();

                etIMC.setText(Double.toString(IMC));

            }
        });
        etHeight.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //aqui você realiza os calculos que precisa e atribui o resultado
                // ao local desejado
                String heightString = etHeight.getText().toString();

                // convert the String into a double
                if (heightString.length() > 0) {
                    height = Double.parseDouble(heightString);
                }

                // read the height out of heightEdit
                String hString = etHeight.getText().toString();

                if (hString.length() > 0) {
                    height = Double.parseDouble(heightString);
                }
                double imc = calcIMC();

                etIMC.setText(Double.toString(imc));
            }

        });
        String htcString = etHTC.getText().toString();

        // convert the String into a double
        if (htcString.length() > 0) {
            htc = Double.parseDouble(htcString);
        }

        rgLevel = (RadioGroup) findViewById(R.id.rgLevels);

        rgLevel.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override

            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // find which radio button is selected
                if (checkedId == R.id.rbL1) {
                    level = 0;
                } else if (checkedId == R.id.rbL2) {
                    level = 401.089;
                } else {
                    level = 848.182;
                }
            }
        });
        Hemat = Htc();
        varResult = calcBleed();
        etResult.setText(Double.toString(varResult));

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client4 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    public void bleedingCalc(View v) {
        Bundle enviarResultado  = new Bundle();
        enviarResultado.putString("Resultado", String.valueOf(etResult));

        Intent intent = new Intent(BleedingMain.this, Calculator.class);
        intent.putExtras(enviarResultado);
        startActivityForResult(intent, CalculateBleed);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CalculateBleed) {
            if (resultCode == RESULT_OK) {
                resultcalc.setText(Double.toString(R.id.etResult));
                TextView t1 = (TextView) findViewById(R.id.etResult);
                t1.setText(data.getStringExtra(String.valueOf(etResult)));
            }
        }
    }

    double calcIMC() {
        return (weight) / (height * height);

    }

    double Htc() {
        return (htc * 20.505);
    }

    double Hemat;

    double calcBleed() {
        return (level) + (smoker) + (gender) + (imc * 17.975) + (Hemat);
    }
    
asked by anonymous 06.11.2016 / 23:14

0 answers