我已经使用十进制格式类将editText变量设置为我的格式变量mark1Format
。但是我不确定如何将新格式变量设置为此result1 = (EditText)findViewById(R.id.mark1);
我的意思是将格式变量设置为R.id.mark1Format。任何人都有解决方案这里?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
result1 = (EditText)findViewById(R.id.mark1);
result2 = (EditText)findViewById(R.id.mark2);
Intent intent = getIntent();
double mark1 = intent.getDoubleExtra("number1", 0);
double mark2 = intent.getDoubleExtra("number2", 0);
//format to two decimal places
DecimalFormat df = new DecimalFormat("#.00");
String mark1Format = df.format(mark1);
String mark2Format = df.format(mark2);
//set the variables on EditTexts like this :
result1 = (EditText)findViewById(R.id.mark1);
result2 = (EditText)findViewById(R.id.mark2);
result1.setText(mark1+"");
result2.setText(mark2+"");
}