简体   繁体   中英

How can I use a double between two classes?

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");
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM