2016-09-21 10 views
0

私はwebview内にGoogleフォームを持つアンドロイドアプリケーションを持っています。 3つの入力ボックス(名前、住所、電話番号)とボタンがあります。私は、この入力値と、アプリケーション内でのさらなる処理のためのボタンのクリックイベントが必要です。私はこれを行うことができる方法はありますか?ボタンクリックを取得し、webview内のGoogleシートからテキストを入力します

Googleのシートを含む断片:

public class Register extends Fragment { 


public Register() { 

} 


@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_register, container, false); 

    WebView webView = (WebView) view.findViewById(R.id.webView); 
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.getSettings().setDomStorageEnabled(true); 
    webView.setWebViewClient(new WebViewClient()); 
    webView.loadUrl("my google sheet"); 

    return view; 
} 
} 

XMLファイル:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#ffffff"> 

<!-- TODO: Update blank fragment layout --> 

<WebView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/webView" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /></RelativeLayout> 

答えて

0

は、各ボタンのリスナーを作成し、リフレクションを使用してイベントを取得:

WebSettings ws = wv.getSettings(); 
ws.setJavaScriptEnabled(true); 
wv.addJavascriptInterface(new Object() 
{ 
    public void performClick() 
    { 
    // Deal with a click on the OK button 
    } 
}, "google_sheet_button"); 

その後HTMLでは、buttonタグから直接呼び出します。

<button type="button" onclick="google_sheet_button.performClick();">google Sheet Save</button> 
関連する問題