我正在从edittext 中获取文本,并对除JellyBean 之外的每个api 版本都有效的值进行一些计算。问题是当我在编辑文本中输入一个数字并按下计算按钮时它会起作用,然后当我将该编辑文本的值更改为其他值并再次按下计算时它不起作用。我需要重新启动应用程序才能使用它。我没有任何可测试的软糖设备,但我的客户为我提供了一个视频,我看到这个事实是真实的。我现在该怎么办?
这是我在那个按钮点击监听器中所做的计算代码
try {
double i = Double.parseDouble(startdate.getText().toString()) / 365;
double j = 1 / i;
double k = Math.pow(d3, j);
double l = k - 1;
double m = l * 100;
annualroi = roundTwoDecimals(m);
investmentyear.setText("Investment periode(Days):"
+ startdate.getText().toString());
annualizeroi.setText("Simple Annualized ROI(%):" + annualroi);
} catch (Exception e) {
e.printStackTrace();
}
这是我的实际活动代码:
public class MainActivity extends Activity implements OnClickListener {
EditText originalinvestment, returnedvalue, startdate;
Button startpick, endpick, calculate, calculateannual;
String posstartdate, postenddate;
static final int DATE_PICKER_DIALOG_ID = 0;
static final int DATE_PICKER_DIALOG_IDTWO = 1;
Date dayofyearone;
Date dayofyeartwo;
double d1;
double d;
double d2;
double d3;
TextView tgainorloss, investmentyear, returninvestment, annualizeroi;
double year;
double gainorloss;
double roi;
double annualroi;
int k1;
int l1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
setContentView(R.layout.activity_main);
initializer();
calculate.setOnClickListener(this);
calculateannual.setOnClickListener(this);
}
private void initializer() {
originalinvestment = (EditText) findViewById(R.id.etoriginalinvestment);
returnedvalue = (EditText) findViewById(R.id.etreturnedvalue);
startdate = (EditText) findViewById(R.id.etstartdate);
calculate = (Button) findViewById(R.id.btncalculate);
tgainorloss = (TextView) findViewById(R.id.txtgainorloss);
investmentyear = (TextView) findViewById(R.id.txtinvestmentterm);
returninvestment = (TextView) findViewById(R.id.txtreturninvest);
annualizeroi = (TextView) findViewById(R.id.txtannualizeroi);
calculateannual = (Button) findViewById(R.id.btncalculateannual);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btncalculate:
getYearDifference();
break;
case R.id.btncalculateannual:
try {
double i = Double.parseDouble(startdate.getText().toString()) / 365;
double j = 1 / i;
double k = Math.pow(d3, j);
double l = k - 1;
double m = l * 100;
annualroi = roundTwoDecimals(m);
investmentyear.setText("Investment periode(Days):"
+ startdate.getText().toString());
annualizeroi.setText("Simple Annualized ROI(%):" + annualroi);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
double roundTwoDecimals(double d) {
return Double.valueOf((new DecimalFormat("#.##")).format(d))
.doubleValue();
}
public void getYearDifference() {
try {
if (!originalinvestment.getText().toString().contentEquals("")
&& !returnedvalue.getText().toString().contentEquals("")) {
d = Double.parseDouble(originalinvestment.getText().toString());
d1 = roundTwoDecimals(Double.parseDouble(returnedvalue
.getText().toString()) - d);
gainorloss = d1;
roi = roundTwoDecimals(100D * (d1 / d));
d3 = (roi / 100) + 1;
tgainorloss.setText("Gain or loss investment($):" + gainorloss);
returninvestment.setText("Return on Investment(%):" + roi);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}