我有 3 EditText 需要从用户输入一个值。在用户能够单击按钮之前,我想确保所有 3 个 EditText 框都有一个值。如果不是,则用户必须无法单击该按钮。我尝试使用“setEnabled”或“setVisibility”,但它们会抛出错误。
EditText numA, numB, numC;
public static class QuadEquation extends Activity{
Button calculate;
EditText numA, numB, numC;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calculator);
calculate = (Button) findViewById(R.id.calculate);
numA = (EditText) findViewById(R.id.numA);
numB = (EditText) findViewById(R.id.numB);
numC = (EditText) findViewById(R.id.numC);
try{
calculate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Double a = (double) 0, b = (double) 0, c = (double) 0;
//Need to convert the string into double.
if (!(numA.getText().toString().equals("") && numB.getText().toString().equals("") && numC.getText().toString().equals(""))){
a = Double.parseDouble(numA.getText().toString());
b = Double.parseDouble(numB.getText().toString());
c = Double.parseDouble(numC.getText().toString());
}