我在本地HTML頁面中顯示圖像,並有一個用於單擊事件的按鈕。當點擊這個按鈕時,我需要調用另一個活動。它正在工作。但是,問題出在另一個後,回到HTML頁面的圖像不顯示和應用程序不工作。Android HTML按鈕onclick事件
<script language="javascript">
function validClick() {
valid.performClick();
document.getElementById("ok").value = "start";
}
function refuseClick(){
refuse.performClick();
document.getElementById("no").value = "Je refuse";
}
<div>
<button type="button" id="ok"
style="font-weight: 700; margin-right: 20px;" onclick="validClick();">Start</button>
</div>
HTML頁面包含圖像:
<li><a class="box" href="products.html" data-transition="fade" > <img src="img/products.png" alt="Products"> <span class="text"> Products</span>
MainActivity:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.about_screen);
WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/index.html");
valid = new Button(this);
valid.setOnClickListener(this);
refuse = new Button(this);
refuse.setOnClickListener(this);
// Enablejavascript
WebSettings ws = webview.getSettings();
ws.setJavaScriptEnabled(true);
// Add the interface to record javascript events
webview.addJavascriptInterface(valid, "valid");
webview.addJavascriptInterface(refuse, "refuse");
}
@Override
public void onClick(View v) {
if (v.equals(valid)) {
Intent i = new Intent(this, CloudReco.class);
startActivity(i);
} else if (v.equals(refuse)) {
//do Something else }
}
您能澄清圖像不顯示,應用程序無法正常工作嗎?您列出的HTML中沒有圖像。 – ksasq
你可以檢查編輯的代碼 – user3351727
我仍然不能確切地告訴你應用程序的意思是不工作,但我已經發布了一些提示,應該會改善你的程序。如果您仍然遇到問題,請發佈問題的確切詳細信息; 「它不工作」太模糊了! :-) – ksasq