组单选按钮
我在组中有 3 个单选按钮,我想在单击单选按钮时调用意图,但是当我单击单选按钮时,我遇到了异常,并且我无法找出我遇到的异常类型。
这是我的代码。
public class Contentstory extends Activity {
RadioButton Child,Adult,Animated ;
RadioGroup radiogroup1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content);
radiogroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
final RadioButton Child = (RadioButton)findViewById(R.id.radio0);
radiogroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (Child.isChecked()){
Intent intent = new Intent(getApplicationContext(),StoryList.class);
Contentstory.this.startActivity(intent);
}
}
});
I have 3 radio button in group and I want to call intent on click of radio button but when I clicked on radio button I got exception and I'm not able to find out what kind of exception I'm getting.
Here is my code.
public class Contentstory extends Activity {
RadioButton Child,Adult,Animated ;
RadioGroup radiogroup1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content);
radiogroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
final RadioButton Child = (RadioButton)findViewById(R.id.radio0);
radiogroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (Child.isChecked()){
Intent intent = new Intent(getApplicationContext(),StoryList.class);
Contentstory.this.startActivity(intent);
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需调用
radiogroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
正确检查单选按钮的 id,因为您的代码没有显示错误,
发布异常,然后我将能够检查 id 出了什么问题?
No need to call
radiogroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
Check id of radio button correctly as your code showing no error,
Post exception then i will be able to check what's going wrong with id?