-1

Phonegap 1.8.1 -- Android API for 2.2 -- jQuery 1.7.1 -- jQueryMobile 1.0

これをテストするために非常に単純なアプリを作成しましたが、動作させることができません。ここにあります。

INDEX.HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>TestApp</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="jquery.mobile-1.1.0/jquery.mobile-1.1.0.min.css"/>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="jquery.mobile-1.1.0/jquery.mobile-1.1.0.min.js"></script>
    <script type="text/javascript">
        function onDeviceReady() {

            document.addEventListener("backbutton", onBackButton);
        }

        function onBackButton(e){
            console.log("C'mon guv! Gimme a chance!");
        }

        document.addEventListener("deviceready", onDeviceReady, false);

    </script>
    <script type="test/javascript" src='cordova-1.8.1.js'></script>

</head>

<body>
<div id="homepage" data-role="page" data-theme="a">
    <div data-role="header">
        <h1>Work with me here</h1>
    </div>

    <div data-role="content">
        I am page 1.
        <a href="#char-1" data-role="button">Next</a>
    </div>
</div>

<div id="char-1" data-role="page" data-theme="a">
    <div data-role="content">HAHAHA!</div>
</div>


</body>
</html>

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="2" android:targetSdkVersion="14"/>
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:resizeable="true"
        android:anyDensity="true" />

    <application android:label="@string/app_name">
        <activity android:name="MyActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest> 

補遺 - 問題は、「deviceready」イベントが発生しないか、コードがイベントにバインドされる前に発生することだと思います。修正方法がわかりません。

提供する必要がある情報が他にある場合はお知らせください..困惑しています。

4

2 に答える 2

1

私の知る限り、戻るボタンを押すイベントは内部では機能していませんonDeviceReady。すべてのページショーでイベントをトリガーする必要があります。私の場合、次のように機能します。

function onDeviceReady(){
    /*Back event handler for all pages navigation*/
    $(document).bind ('pageshow', function (e, data) {
        if ($.mobile.activePage.attr('id') == 'index') {
            document.addEventListener("backbutton", function () { 
                setTimeout( function() {navigator.app.exitApp();}, 100 );
            }, true);
        }
        else{
            document.addEventListener("backbutton", function () {
                setTimeout( function() {$.mobile.changePage("#index");}, 100 );
            }, true);
        }
    });


}

私のアプリケーションでは、最初の画面から戻るボタンを押すとアプリケーションが終了し、いずれかのページ内を押すと自動的に最初のページに移動します。

于 2012-07-17T04:34:10.853 に答える
1

これを認めるのは恥ずかしい。

<script type="test/javascript" src='cordova-1.8.1.js'></script>

test/javascript ではありません... text/javascript です。

:(

于 2012-07-19T01:23:56.487 に答える