Ton*_*ens 2 string double android android-edittext
首先,我是初学者...所以如果我正在做的事情很容易修复(或者一般),我道歉:)
我正在尝试接受用户输入(圈数[int],燃料使用[双]和特征[int]的圈数)来为赛车手创建一个简单的燃料计算器.但是,我无法识别变量.我一直在收到错误,因为我无法在某个类中使用某个函数.我已经分配了XML字段只采用那些类型的数字,所以现在我严格地在java中工作.
我在java编译器中工作,但把它带到Android是我正在学习的另一个过程.
从用户输入计算后,我希望指定的textView更改为正确的答案.我认为这部分是可以的,但是将值赋予数学上可行的值是我遇到问题的地方.
我在这里附上了整个代码(请原谅冗余和评论,让我不要来回寻找公式哈哈).您可以提供的任何帮助将不胜感激!我会尽力从这个应用程序中学习其他与数学相关的活动.
package com.tomcat.carolina.learning;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
//double pracLaps, fuelUsed, featureLaps, textLPGValue, textFuelNeededValue;
public class Fuelsimple extends Activity implements OnClickListener{
EditText fuelUsed, pracLaps, featureLaps;
TextView textLPGValue, textFuelNeededValue;
//efficiency = (pracLaps / fuelUsed);
//fuelNeeded = (featureLaps / efficiency);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fuelsimple);
pracLaps = (EditText) findViewById(R.id.pracLaps);
fuelUsed = (EditText) findViewById(R.id.fuelUsed);
featureLaps = (EditText) findViewById(R.id.featureLaps);
Button gen = (Button) findViewById(R.id.submit);
textLPGValue = (TextView) findViewById(R.id.textLPGvalue);
textFuelNeededValue = (TextView) findViewById(R.id.textFuelNeededValue);
gen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
textLPGValue.setText(getNextDecimal(pracLaps / fuelUsed));
textFuelNeededValue.setText(getNextDecimal(featureLaps/(pracLaps / fuelUsed)));
};
});
Run Code Online (Sandbox Code Playgroud)
我希望这就是你要找的东西:
pracLaps = (EditText) findViewById(R.id.pracLaps);
fuelUsed = (EditText) findViewById(R.id.fuelUsed);
featureLaps = (EditText) findViewById(R.id.featureLaps);
pracLapsVar = Double.parseDouble(pracLaps.getText().toString());
fuelUserVar = Double.parseDouble(fuelUsed.getText().toString());
featureLapsVar = Double.parseDouble(featureLaps.getText().toString());
efficiency = (pracLapsVar / fuelUsedVar);
fuelNeeded = (featureLapsVar / efficiency);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17448 次 |
| 最近记录: |