I am very new to android. Now i am working android html and java script functionality. I have tried to send the data from android page to html page but i didn't succeed. Please tell me how can i do that in android. That a great help for me.
Html page:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script src="index.js"></script>
</head>
<body>
<h1>This is my first webpage</h1>
<p id="demo">A Paragraph.</p>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>
Java script page index.js
function myFunction()
{
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
In the android assets folder i put these files. In the layout i have taken one edit text and one button. For that edit text i got text and i want to update that text to html page. That is task. so i did like
Layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="horizontal" >
<EditText
android:id="@+id/edittext"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="70"/>
<Button
android:layout_width="0dp"
android:layout_weight="30"
android:id="@+id/button"
android:layout_height="40dp"
android:text="Button"/>
</LinearLayout>
<WebView
android:id="@+id/graph"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Activity:
package com.roopasoft.drawtriangle;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
public class HtmlLoad extends Activity implements OnClickListener{
EditText editText;
Button button;
WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
view = (WebView)findViewById(R.id.graph);
editText = (EditText)findViewById(R.id.edittext);
button = (Button)findViewById(R.id.button);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl("file:///android_asset/TextDemo.html");
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button:
String name = editText.getText().toString();
view.loadUrl("file:///android_asset/javascript:myFunction(\""+name+"\")");
break;
}
}
}
When i click my button that name will not updated to edit text. Can you please tell me how can slove that problem.
Thanks Shankar