【发布时间】:2020-10-16 23:39:05
【问题描述】:
我有 3 个复选框,每个复选框旁边是一个用于数据输入的 EditText。如何根据 CheckBox 是否被标记来激活和停用每个 CheckBox 旁边的 EditText?对不起我的英语。
public class MainActivity extends AppCompatActivity {
DecimalFormat df = new DecimalFormat("##,##");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void calcularMedia(View v) {
try {
EditText notaP1 = (EditText) findViewById(R.id.etP1);
EditText notaP2 = (EditText) findViewById(R.id.etP2);
EditText notaP3 = (EditText) findViewById(R.id.etP3);
TextView tvNotaFinal = (TextView) findViewById(R.id.tvNotaMedia);
tvNotaFinal.setText("");
if (notaValida(notaP1.getText().toString(), notaP2.getText().toString(), notaP3.getText().toString())) {
String cad = "PUNTUAIÓN DEL ALUMNO: " + df.format(calculoNota(notaP1.getText().toString(), notaP2.getText().toString(),
notaP3.getText().toString()));
TextView texto = (TextView) findViewById(R.id.tvNotaMedia);
texto.setText(cad);
} else {
Toast tError = Toast.makeText(getApplicationContext(), "Las notas no pueden ser superiores a 10", Toast.LENGTH_SHORT);
tError.setGravity(Gravity.CENTER_HORIZONTAL, 0, 600);
tError.show();
}
} catch (Exception ex) {
Toast tError = Toast.makeText(getApplicationContext(), "Faltan campos por rellenar.", Toast.LENGTH_SHORT);
tError.setGravity(Gravity.CENTER_HORIZONTAL, 0, 600);
tError.show();
}
}
public int calculoNota(String notaP1, String notaP2, String notaP3) {
int notaFinal = (Integer.parseInt(notaP1) + Integer.parseInt(notaP2) + Integer.parseInt(notaP3)) / 3;
return notaFinal;
}
public boolean notaValida(String examen, String practicas, String actitud) {
if (Double.parseDouble(examen) <= 10 && Double.parseDouble(practicas) <= 10 && Double.parseDouble(actitud) <= 10) {
return true;
}
return false;
}
}
【问题讨论】:
-
您应该查看“如何提问”链接stackoverflow.com/help/how-to-ask。您尝试过的代码和示例产品会有所帮助stackoverflow.com/help/minimal-reproducible-example