亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 Android Studio 在 Java 中計算總和

如何使用 Android Studio 在 Java 中計算總和

智慧大石 2023-04-13 14:48:35
我剛剛使用 Android Studio 學習了 Java。我的代碼錯誤使用整數來計算總和。我嘗試將字符串解碼為整數但仍然出錯。protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        edtvalue = (EditText) findViewById(R.id.value);        final Spinner edtjw = (Spinner) findViewById(R.id.spinner1);        txtpa = (TextView) findViewById(R.id.pa);        txttotal = (TextView) findViewById(R.id.total);        btncount.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                String value = edtvalue.getText().toString().trim();                String jw = edtjw.getSelectedItem().toString().trim();                double h = Double.parseDouble(value);                double j = Double.parseDouble(jw);                String numbertostring = String.format ("%.2f", (0.02*h));                String numbertostring2 = String.format ("%.2f", (0.025*h));                String numbertostring3 = String.format ("%.2f", (0.0275*h));                if (j == 1){                    txtpa.setText(numbertostring);                } else if (j ==2){                    txtpa.setText(numbertostring);                } else if (j ==3){                    txtpa.setText(numbertostring);                } else if (j ==4){                    txtpa.setText(numbertostring2);                } else  if (j ==5){                    txtpa.setText(numbertostring3);                } else {                    txtpa.setText(0);                }                int tot = (h*j)+txtpa;                txttotal.setText("Total : "  + tot);}}
查看完整描述

1 回答

?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

通過查看代碼片段,您應該從中獲取txtpa類型為 的字符串值TextView,然后將其解析為double

double tot = (h*j)+Double.parseDouble(txtpa.getText().toString());


查看完整回答
反對 回復 2023-04-13
  • 1 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號