I want to build a currency calculator. There is a plain text and a button. if somebody scribe a number in the plain text and press the button a dialog will be shown.

BUT the number of the plaintext is everytime 2.1311!

here is my code

//this is the Main Activity


public class MainActivity extends AppCompatActivity {
public void PesoInEuro (View view){

    EditText Peso = findViewById(R.id.EuroBetrag);

    String amountPeso = Peso.getText().toString();

    double amountPesodouble = Double.parseDouble(amountPeso);

    double amountEurodouble = amountPesodouble * 46.85;

    String amountEuro = String.valueOf(amountEurodouble);


    Button buttonOne = (Button) findViewById(R.id.PesoEuro);

    buttonOne.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openDialog();
        }
    });
}
public void openDialog(){
    DiaPesoEuro exampleDialog = new DiaPesoEuro();
    exampleDialog.show(getSupportFragmentManager(), "example Dialog");
}

1 Answers

0
Shayan Khaksar On

First of all, it's a good practice to find your views in the OnCreate method. Secondly, you have read and calculate your values when the user hit the button. In the code above, you got the data in the PesoInEuro, and when the user presses the button, it shows the retrieved data and your calculation is based on them.