2 回答
TA贡献1869条经验 获得超4个赞
对于您的第一个问题,请执行以下操作:
public void eightNumber(View view) {
TextView t = (TextView) findViewById(R.id.textView);
temp = t.getText();
temp = temp + "8"
//convert the input number to double to avoid extra zero before digits (05)
double tempNumber = Double.parseDouble(temp);
//convert our double number back to string, to use it in textView.setText method
temp = String.valueOf(tempNumber);
//to avoid redundant ".0" after integer numbers:
//if 2 last digits of the number is .0, we delete it
if(temp.lastIndexOf(".0") == temp.length() - 2){
temp = temp.substring(0, temp.length() - 2);
}
t.setText(temp);
}
以此类推所有 9 位数字。但是你的第二个问题,你只需要颠倒 if 条件:
public void pressDot(View view)
{
TextView t = (TextView) findViewById(R.id.textView);
doot=t.toString();
if (!doot.contains(dooot)) {
t.append(".");
}
}
并且不需要 else 块。如果您需要更多帮助,请告诉我。
TA贡献2051条经验 获得超10个赞
发现一个错误:
public void pressDot(View view)
{
TextView t = (TextView) findViewById(R.id.textView);
doot=t.getText().toString(); //should be this
if (doot.contains(dooot))t.append(".");
else t.append("");
}
添加回答
举报