android.widget.RadioGroup cannot be cast to android.widget.Button
publicclassSelectlevelextendsActivity{//声明intlevel=0;//困难等级RadioGroupradg;RadioButton...
public class Selectlevel extends Activity {
//声明
int level = 0;// 困难等级
RadioGroup radg;
RadioButton btn;
Button confir;
static int times = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selectlevel);
//初始化
confir = (Button) findViewById(R.id.done);
//btn=(RadioButton) findViewById(R.id.Hard);
radg=(RadioGroup) findViewById(R.id.Selectlevel);
// 获得等级
confir.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
btn=(RadioButton) findViewById(radg.getCheckedRadioButtonId());
if (btn.getId() == ((RadioButton) findViewById (R.id.Hard)).getId() )
times = 5;
else if (btn.getId() ==( (RadioButton) findViewById(R.id.Middle)).getId())
times = 10;
else
times = 15;
Intent intent = new Intent(Selectlevel.this, Letganme.class);
startActivity(intent);
}
});
} 展开
//声明
int level = 0;// 困难等级
RadioGroup radg;
RadioButton btn;
Button confir;
static int times = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selectlevel);
//初始化
confir = (Button) findViewById(R.id.done);
//btn=(RadioButton) findViewById(R.id.Hard);
radg=(RadioGroup) findViewById(R.id.Selectlevel);
// 获得等级
confir.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
btn=(RadioButton) findViewById(radg.getCheckedRadioButtonId());
if (btn.getId() == ((RadioButton) findViewById (R.id.Hard)).getId() )
times = 5;
else if (btn.getId() ==( (RadioButton) findViewById(R.id.Middle)).getId())
times = 10;
else
times = 15;
Intent intent = new Intent(Selectlevel.this, Letganme.class);
startActivity(intent);
}
});
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询