简体   繁体   English

我怎样才能在两个班级之间使用双?

[英]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! 但明文的数量是每次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. 首先,在OnCreate方法中查找视图是一种很好的做法。 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. 在上面的代码中,您获得了PesoInEuro中的数据,当用户按下按钮时,它会显示检索到的数据,并且您的计算基于它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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