添加自定义view出现空指针异常
2012-02-02 01:08
507 查看
代码片段:
老是报空指针异常,最后发现原来是要
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View scenemode = inflater.inflate(R.layout.scenemode, null); new AlertDialog.Builder(MyGridView.this) .setTitle("情景模式设置") .setView(scenemode) .setPositiveButton("ok", null) .setNegativeButton("cancle", null) .show(); /*为RadioGroup添加监听事件*/ final RadioButton rb1 = (RadioButton)findViewById(R.id.rb1); final RadioButton rb2 = (RadioButton)findViewById(R.id.rb2); final RadioButton rb3 = (RadioButton)findViewById(R.id.rb3); final RadioButton rb4 = (RadioButton).findViewById(R.id.rb4); final TextView tv = (TextView)findViewById(R.id.tv); RadioGroup rg = (RadioGroup)scenemode.findViewById(R.id.rg); rg.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(checkedId == rb1.getId()) {
老是报空指针异常,最后发现原来是要
final RadioButton rb1 = (RadioButton)findViewById(R.id.rb1);改为final RadioButton rb1 = (RadioButton)scenemode.findViewById(R.id.rb1);
以下的几个控件都要改
相关文章推荐
- 0819-TableView(tableVeiw控件的代理)(tableView单组 lol数据展示)(tableView-汽车品牌logo 右侧a-z)(KVC)(tableView - 添加删除按钮出现)(自定义代理delegate)(内存)
- 在ScollView中添加自定义的listView或者WebView 出现抢占焦点的问题
- findViewById自定义控制时出现空指针异常
- UITableViewCell添加自定义view,在cell选中高亮时,view消失,取消高亮时,view又出现
- uitableview contentview 添加子view出现约束错误
- ios UIImagePickerController 添加一个自定义的view。
- XCode添加自定义framework运行时出现dyld: Library not loaded的解决方法
- 自定义View- 编译时出现aapt.exe finished with non-zero exit value 1错误的解决方法
- Android自定义View时添加自己的事件监听器
- 自定义View添加到Viewgroup中layoutparams为空的记录
- 添加 自定义的view,并显示在最前端
- 如何自定义ImageView---并让其渐变出现(李刚老师)
- XCode7添加自定义framework 比如加入swiftjson.framework框架后运行真机出现dyld: Library not loaded的解决方法
- iOS - 自定义alertView,继承自UIView,可以添加子视图,标题图片+文字
- 自定义ViewGroup动态添加删除Tab
- 自定义view 中间添加汉字
- TextView的一些高级应用(自定义字体、显示多种颜色、添加阴影)
- 自定义ViewGroup,并添加高仿雪球app分享弹出动画。
- Android中自定义ImageView添加文字说明详解
- 自定义添加View