我正在尝试根据用户输入来计算平均值。现在,我已经掌握了基础知识。但是我想在单击addGradeButton时添加2个具有约束的EditText。我已经搜索了一个小时的观看时间,但是找不到任何可以做的事情。总的来说有人可以帮助我。
欢迎任何解释或提示等!
final TextView averageView = findViewById(R.id.averageView);
final String averageText = getString(R.string.average);
final Button calculateButton = findViewById(R.id.calculateAverageButton);
final Button addGradeButton = findViewById(R.id.addGradeButton)
calaculateButton.setOnClickListener(new View.onClickListener() {
@SupressLint("SetTextI18n")
public void onClick(View v) {
double grade[] = {Double.parseDouble(((EditText) findViewById(R.id.grade1)).getText().toString());
double weight[] = {Double.parseDouble(((EditText) findViewById(R.id.weight1)).getText().toString());
double weightTotal = weight[0]; double sum = grade[0] * weight[0]
double average = sum / weightTotal
@SuppressLint("DefaultLocale") String averageResult = String.format(%.2f, average);
averageView.setText(averageText + " " + averageResult);