使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
来源:互联网 发布:软件防止破解 编辑:程序博客网 时间:2024/05/20 06:06
isInEditMode:
Indicates whether this View is currently in edit mode. A View is usually in edit mode when displayed within a developer tool. For instance, if this View is being drawn by a visual user interface builder, this method should return true. Subclasses should check the return value of this method to provide different behaviors if their normal behavior might interfere with the host environment. For instance: the class spawns a thread in its constructor, the drawing code relies on device-specific features, etc. This method is usually checked in the drawing code of custom widgets.
如果在自定义控件的构造函数或者其他绘制相关地方使用系统依赖的代码,会导致可视化编辑器无法报错并提示:Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
比如:
public class LockRelativeLayout extends RelativeLayout {
private Handler mainHandler = null; //与主Activity通信的Handler对象
public LockRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs, 0);
mContext = context;
if (isInEditMode()) { return; }
mainHandler = ((SPActivity)mContext).getMHandler();
}
}
如果不加上if (isInEditMode()) { return; },标红处代码会导致可视化编辑报错
转自:http://blog.csdn.net/lamp_zy/article/details/9405925
- isInEditMode解决可视化编辑器无法识别自定义控件的问题
- 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- (4.1.36.9)使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- 解决可视化编辑器无法识别自定义控件的问题
- 功能测试自动化视频---解决自定义控件的无法识别问题
- 自定义控件无法在Eclipse的Android界面编辑器的可视化模式下显示
- WordPress可视化编辑器问题的解决
- 解决WPF引用无法识别的问题
- 解决 avformat_alloc_context无法识别的问题
- 解决TSLIB无法识别触摸屏的问题
- QTP学习笔记(一):安装篇,解决QTP无法识别控件对象的问题
- 解决VS2010使用mscomm控件无法接收数据的问题
- 自定义的view无法在layou视图中查看 ,How to use isInEditMode()
- Android使用自定义控件遇到的问题及解决
- 自定义控件id无法被识别的解决方法
- Linux 画图
- Web基础入门(表格)-使用表格嵌套的形式制作一个简单的网页布局
- RESTful API 设计指南
- docker官方文档
- 记一次难查的崩溃
- 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- nodejs与koa入门
- iOS -(仿美团)城市选择器 + 自动定位 + 字母索引
- Ajax参数说明
- 计算机中丢失 xxx.dll 怎么办
- ios开发中pod命令介绍
- Java基础学习总结(11)——JSTL标签库
- “Hello,Github!"——如何配置并上传一个已有项目到Git上
- 如何开发出一款仿映客直播 APP 项目实践篇 -【采集篇 】