我遇到以下问题:
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);
};
答案 0 :(得分:0)
为什么你故意使你的代码复杂化,你可以简单地写:
if (Cubo.isChecked())
{
//do whatever you want to do
}
isChecked方法返回一个布尔值,因此您可以直接在if条件
中写入它还有一件事,你为什么要放一个分号[;在你的else语句关闭大括号[}]之后,用另一个右大括号[}]
替换那个分号答案 1 :(得分: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;
}
}