使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
2015-01-29 01:04
309 查看
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; },标红处代码会导致可视化编辑报错
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; },标红处代码会导致可视化编辑报错
相关文章推荐
- 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- (4.1.36.9)使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题(转)
- 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题
- 解决可视化编辑器无法识别自定义控件的问题
- android窗口泄漏,isInEditMode解决可视化编辑器无法识别自定义控件的问题
- isInEditMode解决可视化编辑器无法识别自定义控件的问题
- RICOH Aficio打印机使用U盘打印无法识别的问题解决
- 使用keil5.10软件仿真教程以及解决软件仿真unknown signal无法识别引脚端口问题
- 功能测试自动化视频---解决自定义控件的无法识别问题
- 解决WordPress无法使用可视化编辑器的问题
- linux复制虚拟机网卡无法使用及新增网卡不被识别问题解决
- 【ANDROID】解决使用ZXING扫码,距离近无法识别的问题。
- rtl8723bs linux网卡驱动识别问题,无法使用无线的解决方法
- 解决WCF服务使用net.tcp协议时出现“无法识别该URI前辍”的问题
- 解决AJAX中使用UpdatePanel后再用Response.Write();等无法弹出对话框问题 3法
- Eclipse安装MyEclipse后,新插件无法识别问题解决
- 操作系统无法识别光驱问题解决
- 解决AJAX中使用UpdatePanel后再用Response.Write();等无法弹出对话框问题 3法