I have a value inside javascript variable and would like to value of that variable in Sting variable in Android code. I have one webview inside that I created one combo box using HTML Code. That combo box has Five elements say "white',ivory,..etc and now upon selecting those I need to get the selected value from the combo box and pass to java function.
public class UserInterface extends Activity { WebView _webview; LinearLayout _linearLayout; private Handler mHandler = new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); Main(); } public void Main() { _linearLayout = new LinearLayout(this); _webview = new WebView(this); _linearLayout.addView(_webview, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); setContentView(_linearLayout); _webview.getSettings().setJavaScriptEnabled(true); _webview.getSettings().setPluginsEnabled(true); _webview.getSettings().setAllowFileAccess(true); _webview.setWebChromeClient(new WebChromeClient()); _webview.addJavascriptInterface(this, "Question"); _webview.loadData(GetHTML(), "text/html", "utf-8"); } public String GetHTML() { String HTML = "" + "<HTML>" + "<HEAD>" + "<TITLE>Radio Button onClick Handler</TITLE>" + "<SCRIPT LANGUAGE=\"JavaScript\">" +"function function1(colors) {" +"var col = (colors.options[colors.selectedIndex].value);" +" if (col) {" +" document.bgColor = col;" +" } " +"</script>" + "</HEAD>" + "<BODY>" +"<form>" +"<b> Hello </b>" //+"<select name=\"colors\" onChange=\"window.Question.function1(this);\">" +"<select name=\"colors\" onChange=\"window.Question.OnJsClick_SelectedItem(' string value');\">" +"<option value=\"white\" selected>White</option>" + "<option value=\"cyan\">Cyan</option>" + "<option value=\"ivory\">Ivory</option>" + "<option id=\"myO\" value=\"blue\">Blue</option>" +"</select>" +"</form>" + "</BODY>" + "</HTML>"; return HTML; } public void OnJsClick_SelectedItem(final String str) { mHandler.post(new Runnable() { //@Override public void run() { getValue(str); } }); } public String getValue(String str) { _webview.loadUrl("javascript:function1(colors)"); Toast.makeText(this, "Under getValue " + str, Toast.LENGTH_SHORT).show(); return str; } } -- --------------------------------- Thanks & Regards, Vivek Tamrakar -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en