Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 2.2上WebView中的绑定事件_Android_Jquery Mobile_Android Webview - Fatal编程技术网

Android 2.2上WebView中的绑定事件

Android 2.2上WebView中的绑定事件,android,jquery-mobile,android-webview,Android,Jquery Mobile,Android Webview,我无法使用WebView将点击和滑动事件绑定到我的应用程序中,该WebView具有简单的示例代码,可以在浏览器中正常工作。我用的是JQuery手机。有什么想法吗 <!DOCTYPE html> <html> <head> <title>jQuery Mobile Events</title> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/j

我无法使用WebView将点击和滑动事件绑定到我的应用程序中,该WebView具有简单的示例代码,可以在浏览器中正常工作。我用的是JQuery手机。有什么想法吗

<!DOCTYPE html> 
<html> 
<head> 
<title>jQuery Mobile Events</title> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-           1.0a3.min.css" />
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
<script type="text/javascript">
$( function() {
$('body').bind( 'taphold', function( e ) {
alert( 'You tapped and held!' );
e.stopImmediatePropagation();
return false;
} );  
$('body').bind( 'swipe', function( e ) {
alert( 'You swiped!' );
e.stopImmediatePropagation();
return false;
} );  
} );
</script>  
</head>
<body> 
<div data-role="page" id="home">
<div data-role="header">
<h1>jQuery Mobile Events</h1>
</div>
<div data-role="content"> 
<p>Try:</p>
<ul>
  <li>Tapping and holding</li>
  <li>Swiping</li>
</ul>
</div>
</div>
</body>
</html>
下面是Javascript界面:

import java.io.IOException;
import android.content.Context;
import android.widget.Toast;

public class JavaScriptInterface {
Context mContext;
AudioRecord audiorecord;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
    mContext = c;
}

/** Show a toast from the web page */
public void showToast(String toast) {
    Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}

// OnSwipe() here?
}
所以我可能应该在这里添加方法,当检测到滑动时,应该在JQuery中用Android.onswip()调用它?为什么上面的JQuery移动代码不能用于导航?WebView不应该像web浏览器一样工作吗

  • 您应该展示如何实现JavaScriptInterface
  • 从JS到实际的Android JS桥,似乎没有任何传播。在JS代码中,应该调用Android.onswip()之类的函数,并在JavaScriptInterface中实现onswip

  • 提示:jQuery有一个比1.5(1.5.1和1.5.2)更新的版本
    import java.io.IOException;
    import android.content.Context;
    import android.widget.Toast;
    
    public class JavaScriptInterface {
    Context mContext;
    AudioRecord audiorecord;
    /** Instantiate the interface and set the context */
    JavaScriptInterface(Context c) {
        mContext = c;
    }
    
    /** Show a toast from the web page */
    public void showToast(String toast) {
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
    }
    
    // OnSwipe() here?
    }