-1

我对以下情况有疑问:

if (Cuadrado.isChecked() == true)

这是完整的代码:

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {

    String dato5 = DatoMath.getText().toString();

    if (Cubo.isChecked()==true) {

        if (dato5.equals("")) {
            Toast toast = Toast.makeText(getApplicationContext(), "no hay datos", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER | Gravity.LEFT, 0, 0);
            toast.show();
        } else {
            int datofinal = Integer.parseInt(dato5);
            int final3 = (int) Math.pow(datofinal, 2);

            Resultado.setText("" + final3);};

    if (Cuadrado.isChecked() == true) {

        if (dato5.equals("")) {
                    Toast toast = Toast.makeText(getApplicationContext(), "no hay datossssss", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT, 0, 0);
                    toast.show();

        } else {
                    int datofinal2 = Integer.parseInt(dato5);
                    int final4 = (int) Math.pow(datofinal2, 3);

                    Resultado.setText("" + final4);

        };
4

2 回答 2

0
 @Override 
 public void onCheckedChanged(RadioGroup group, int checkedId){
switch(checkedId){
 case R.id.rbtn1:
 // radio button 1 checked related code
 break;
 case R.id.rbtn2:
 // radio button 2 checked related code
 break;
 }

}
于 2014-11-29T19:46:16.730 回答
0

为什么要故意使代码复杂化,您可以简单地编写:

if (Cubo.isChecked())
{
//do whatever you want to do
}

isChecked 方法返回一个布尔值,因此您可以直接将其写入 if 条件中

还有一件事,你为什么要放一个分号[; ] 在你的 else 语句右大括号 [ } ] 之后,用另一个右大括号 [ } ] 替换该分号

于 2014-11-29T19:15:51.230 回答