im пытается сделать кнопку, которая показывает предупреждение на телефоне Android, но ничего не происходит, кнопки правильно отображаются (у меня есть jquery, jquery mobile, js в папке с ресурсами)
...
getWindow().requestFeature(Window.FEATURE_PROGRESS);
WebView webview = new WebView(this);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
setContentView(webview);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl("file:///android_asset/index.html");
webview.addJavascriptInterface(this,"alerts");
setContentView(webview);
}
public void showAlert() {
AlertDialog alert = new AlertDialog();
AlertDialog.Builder builder = new AlertDialog.Builder(main);
builder.setTitle("Test WORKED?");
builder.setMessage("Yes if you see -_-");
alert = builder.create();
alert.show();
}
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="file:///android_asset/jquery.mobile-1.4.2.min.css" />
<script src="file:///android_asset/jquery-2.1.0.min.js"></script>
<script src="file:///android_asset/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<button type="submit" onclick="javascript:showalert();">ShowAlert</button>
<script>
$(document).ready(function showalert() {
alerts.showAlert();
)};
</script>
</body>
</html>
и другой вопрос: как мне сопоставить такую кнопку jquery, чтобы что-то сделать:
<button class="ui-btn ui-btn-inline">Button</button>
ваш код имеет ошибку скрипта.
<script>
$(document).ready(function showalert() {
alerts.showAlert();
)}; //<----- replace please .. });
</script>
а потом
добавить аннотацию?
@JavascriptInterface
public void showAlert() {
AlertDialog alert = new AlertDialog();
AlertDialog.Builder builder = new AlertDialog.Builder(main);
builder.setTitle("Test WORKED?");
builder.setMessage("Yes if you see -_-");
alert = builder.create();
alert.show();
}