0

我是编程 phonegap 应用程序的新手。我已经证明了一个简单的 phonegap 应用程序示例,并且在三星 Galaxy Mini 上运行良好,但在 Android 模拟器中却不行。问题是,当我单击 html 中的特定按钮时,我想显示文本。

应用程序代码如下所示:

import android.os.Bundle;
import org.apache.cordova.*;

public class cordovaExample extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();

        MyClass js = new MyClass(this,appView);
        appView.getSettings().setJavaScriptEnabled(true);
        appView.addJavascriptInterface(js, "JS");

        super.loadUrl(Config.getStartUrl());
    }
}

public class MyClass 
{
     private WebView mAppView;
      private DroidGap mGap;
      Activity activity;

      public MyClass(DroidGap gap, WebView view)
      {
        mAppView = view;
        mGap = gap;
      }

      public String getText()
      {
          return "Hello World";
      }
}

HTML 代码:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />

        <title>Hello World</title>

         <script type="text/javascript" src="cordova-2.5.0.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
            function Showessage()
            {
             var element = document.getElementById('time');
             element.innerHTML = 'First Message :'+  window.JS.getText()  + '<br />';
              //alert('hello');
            }
        </script>
    </head>
    <body>
        <div class="app">
            <h1 class="event received" >Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received"  id ="time" onclick="Showessage()">Device is Ready</p>

            </div>
        </div>
    </body>
</html>
4

1 回答 1

0

你不必加载 corodova.XXjs 只是 cordova.js 脚本。

所以包含应该是:

<script type="text/javascript" src="cordova.js"></script>
<!--- NOT  <script type="text/javascript" src="cordova-2.5.0.js"></script> -->
于 2013-06-27T19:04:25.677 回答