Showing posts with label android java script demo. Show all posts
Showing posts with label android java script demo. Show all posts

Sunday 8 June 2014

Android accessing html control inside Java class| Getting html field value inside android activity class

Hello Friends,
                This is my another android tutorial. In this android demo I am going to
cover following parts:

1. Showing Android Login form in web view or loading html file in web view.
2. Getting the control  of log in button click,user name and password value inside
    our java class.
3. Checking the field validation inside  our java code.
4. Calling web service method based on valid user name and password.

Source Code:

1. Login.html :  This is my html file in which there is two edittext and a login button.
                           When I m clicking on login Button  I am checking the value of both
this text field inside my java class and if it is valid   then I am calling my login service

<!DOCTYPE html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Login Form</title>
<link rel="stylesheet" href="style.css">
<script type="text/javascript">
  function showAndroidToast() {
   var name = document.getElementById("loginName").value;
   var password = document.getElementById("password").value;

 <section class="container">
  <div class="login">
   <h1>Login to Android Developer Solutions</h1>
     <input type="text" name="login" id="loginName" value=""
      placeholder="Username or Email">
     <input type="password" name="password" id="password" value=""
    <p class="remember_me">
     <label> <input type="checkbox" name="remember_me"
      id="remember_me"> Remember me
    <p class="submit">
     <input type="submit" name="commit" value="Login"

  <div class="login-help">
    Forgot your password? <a href="index.html">Click here to reset

 <section class="about">
  <p class="about-author">
   &copy; 2013&ndash;2014 <a
    href="" target="_blank">Android
    Developer Solution</a><br> By <a
    href="" target="_blank">Mukesh



package com.mukesh.webview;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends Activity {

 protected void onCreate(Bundle savedInstanceState) {

  WebView webView = (WebView) findViewById(;

  WebSettings webSettings = webView.getSettings();
  webView.addJavascriptInterface(new WebAppInterface(this), "Android");


Download Code : WebView Demo

Enjoy Codiing....
Cheers :)


Copyright @ 2013 Android Developers Blog.