Feb 23, 2011

Hoe to Create and Use Html File in android

Final Out Put 
 This is very Interesting Code ,Generally when you want to developing any web related pages that time
 we should use html , why because html supports any web browser ,

creating html file in android project :
 1- > create project  and expand it
 2-> right click on assets folder
                                    -> choose New
                                    -> choose others
                                    ->in general folder
                                              -> choose file
                                              -> type some file name with  .html extension (index.html)
                                                      -> click on finish

 writing some code into html file :
       --> simply right click on html folder
       --> choose open with text editor
 write some html code ( like this ) :


<body bgcolor="cyan">
   <table align=""center">
   <th cellpadding=3 align="right">Vizser Employees</th>
   <tr>     <th> Name </th>   <th> Platform </th>   <th> Role</th>     </tr>
   <tr>     <td> Subbu </td>   <td> Java  </td>    <td> MD</td>      </tr>
   <tr>      <td> RajKumar </td>   <td> Testing   </td>   <td> Admin</td>     </tr>
   <tr>  <td> Satish </td>   <td> Php </td>  <td> Senior Developer</td>    </tr>
   <tr>  <td> Madan </td>  <td> Designer </td>  <td> Senior Designer</td>    </tr>
   <tr>  <td> Ramu  </td>  <td> Iphone </td>  <td> Developer</td>    </tr>

mainclass :

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class SravanWebView extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        WebView webview=(WebView)findViewById(R.id.webview1);
        webview.loadUrl("file:///android_asset/index.html");  // opening  html page from assets folder
        webview.setWebViewClient(new SravanWebViewClient());

client view :

import android.webkit.WebView;
import android.webkit.WebViewClient;

public class SravanWebViewClient extends WebViewClient
public boolean shouldOverrideUrlLoading(WebView view, String url)
return true;


main.xml code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:text="Sravan Web View Demo"

Then in your activities onCreate method you'll need to find the reference to your webview and call the load URL method with the filepath to your html file.
WebView wv = (WebView) findViewById(R.id.web_engine);
for this example to work you'll have to put your html file into the assets folder in your project. If you are trying to view your html file without creating an application it may be trickier. On actual devices I know you can put an html file onto the SD card and navigate to it with a file manager program and open it with Offline Browser
for project source code click here (SravanWebView):  ClickMe
Creatin Html File in project 

for Loading any web site code : Click Here

1 comment:

  1. nice post... i want edit the html file ... or i want to underline the word or sentence in run time..

    please help, thanks in advance