使用CordovaWebView在自定义视图中使用View.isInEditMode() [英] Use View.isInEditMode() in your custom views with CordovaWebView

查看:213
本文介绍了使用CordovaWebView在自定义视图中使用View.isInEditMode()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CordovaWebView开发应用程序,并且已在web_view.xml文件中添加了以下代码.

I am developing application with CordovaWebView and i have added the below code in web_view.xml file.

<org.apache.cordova.CordovaWebView
        android:id="@+id/cordovaWebView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

我已经实现了CordovaInterface的方法.现在,我的设计页面显示以下错误消息.

I have implemented methods from CordovaInterface. Now my design page showing the following error message.

提示:在自定义视图中使用View.isInEditMode()可以在以下情况下跳过代码: 在Eclipse中显示

Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse

有人可以告诉我如何解决吗?

Could anyone please tell me that how to resolve it?

推荐答案

isInEditMode()应该在自定义视图构造函数中使用.尝试以下代码:

isInEditMode()should be used inside the Custom View constructor. Try the following code:

public class GraphView extends View implements Grapher
    {

     public GraphView(Context context, AttributeSet attrs) {
            super(context, attrs);
            if(!isInEditMode())
             init(context);
        }

        public GraphView(Context context) {
            super(context);
           if(!isInEditMode()){
            touchHandler = new TouchHandler(this);
            init(context);
          }
        }

用CordovaWebview替换GraphView.

Replace GraphView with your CordovaWebview.

View.isInEditMode()

指示此视图当前是否处于编辑模式.当在开发人员工具中显示时,视图通常处于编辑模式.例如,如果此视图是由可视用户界面构建器绘制的,则此方法应返回true.如果子类的正常行为可能会干扰宿主环境,则子类应检查此方法的返回值以提供不同的行为.例如:该类在其构造函数中产生一个线程,绘图代码依赖于特定于设备的功能,等等.通常在自定义小部件的绘图代码中检查此方法.

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.

这篇关于使用CordovaWebView在自定义视图中使用View.isInEditMode()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆