I have 3 CheckBoxes and next to each of them is an EditText for data-entry. How do I activate and deactivate the EditText next to each CheckBox depending on whether the CheckBox is marked or not? Sorry for my English.
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;
}
}