2016-11-15 41 views
1

我想製作一個網頁瀏覽計算器。讓我們有一個HTML基本計算器UI。從html獲取輸入類型值到android

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Calculator</title> 
    <link href='https://fonts.googleapis.com/css?family=Orbitron' rel='stylesheet' type='text/css'> 

</head> 
<body> 
<form action="" name="calc"> 
    <input type="text" name="screen" disabled> <br> 
    <hr> 
    <input type="button" value="&radic;" onclick="calc.screen.value = Math.sqrt(calc.screen.value);"> 
    <input type="button" value="CE" onclick="calc.screen.value = ''"> 
    <input type="button" value="C" onclick="calc.screen.value = ''"> 
    <input type="button" value="&larr;" onclick="calc.screen.value = calc.screen.value.slice(0,-1);"> <br> 

    <input type="button" value="7"> 
    <input type="button" value="8"> 
    <input type="button" value="9"> 
    <input type="button" value="+"> 

    <br> 

    <input type="button" value="4"> 
    <input type="button" value="5"> 
    <input type="button" value="6"> 
    <input type="button" value="-"> 

    <br> 

    <input type="button" value="1"> 
    <input type="button" value="2"> 
    <input type="button" value="3"> 
    <input type="button" value="*"> 

    <br> 

    <input type="button" value="0"> 
    <input type="button" value="."> 
    <input type="button" value="="> 
    <input type="button" value="/"> <br> 
</form> 
</body> 
</html> 

現在,我想從一個按鈕獲得價值,然後我將在android java類中進行計算。之後,最終結果將以HTML格式顯示。

如何從HTML輸入輸入值到android並傳回?

回答

0

您需要使用Android JavaScriptInterface類從html輸入字段中獲取數據。

JavaScriptInterface有processFormData()方法以字符串形式返回數據。

然後你可以處理這個數據你想要的。

you found some example here