Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Display the Html content page wise using webview in android?

hi i create simple app to display html page in webview i use the webview and display the page load time like this.

Display first time load the data

After this Disable the scroll and use the next and previous button to back and forward contain. So my code is below.

First onCreate display add webview and load the html file.

        mainWebView = (WebView) findViewById(R.id.mainWebView);
    mainWebView.setVerticalScrollBarEnabled(false);
    mainWebView.setHorizontalScrollBarEnabled(false);
    mainWebView.getSettings().setJavaScriptEnabled(true);
    mainWebView.setWebViewClient(new MyWebClient());
    mainWebView.setPictureListener(new MyPictureClass());

    mainWebView.loadUrl("file:///android_asset/chapter-001.html");

after use the MyWebclient Class for get the Height and width for mainwebview.

class MyWebClient extends WebViewClient 
    {
        @Override
        public void onPageFinished(WebView view, String url) 
        {
            System.err.println("Page Finish Call");
            lanscapHeight = protraitHeight = findHeight = mainWebView.getHeight();
            System.err.println("Find     Height->"+findHeight);
            System.err.println("Portait  Height->"+protraitHeight);
            System.err.println("Landscap Height->"+lanscapHeight);


        }
    }

after this use the myPictureClass to get the webView contain length.

class MyPictureClass implements PictureListener
    {
        @Override
        public void onNewPicture(WebView view, Picture picture) 
        {   

                proTraitContain = mainWebView.getContentHeight();

                System.err.println("picture Class Call-->"+proTraitContain);
        }
    }

after this.create button next and previous to display the next and previous page.so use the SimpleOnGestureListener to Detect touch event.

 btnNext = (Button) findViewById(R.id.btnNext);
        btnNext.setOnTouchListener(this);
        btnPrev = (Button) findViewById(R.id.btnPrev);
        btnPrev.setOnTouchListener(this);

Override touch Method.

 @Override
        public boolean onTouch(View view, MotionEvent event) 
        {
            if (view == btnNext)
            {
                btnClickFlage = true;
                gestureDetector.onTouchEvent(event);
            } else 
            {
                btnClickFlage = false;
                gestureDetector.onTouchEvent(event);
            }
            return false;
        }

implement the SimpleGestureListener class as Below.

class MyGesture extends SimpleOnGestureListener 
    {
        @Override
        public boolean onSingleTapUp(MotionEvent e)
        {

            super.onSingleTapUp(e);

                    System.err.println("Display Total Contain For Protrait -->"+proTraitContain);
                    System.err.println("Before Height-->" + findHeight);

                    if (btnClickFlage) 
                    {



                        if (findHeight > (proTraitContain+protraitHeight)) 
                        {
                            if(restProtraitFlag)
                            {
                                System.err.println("If part In side Flag-->"+findHeight);
                                findHeight=findHeight+protraitHeight;
                                restProtraitFlag=false;
                                //findHeight=findHeight+protraitHeight;
                                mainWebView.scrollTo(0, findHeight);
                                System.err.println("If part In side Flag-->"+findHeight);
                            }else
                            {
                                mainWebView.loadUrl("file:///android_asset/chapter-002.html");
                                restProtraitFlag=true;
                            }
                        } 
                        else
                        {
                            if(protraitFlag)
                            {
                                if(findHeight==protraitHeight)
                                {
                                    findHeight = protraitHeight;
                                }else
                                {
                                    findHeight = findHeight + protraitHeight;   
                                }
                                protraitFlag=false;
                            }else
                            {
                                findHeight = findHeight + protraitHeight;
                            }
                            mainWebView.scrollTo(0, findHeight);
                        }
                    }
                    else
                    {
                        restProtraitFlag=true;
                        if (findHeight<=0)
                        {
                            mainWebView.loadUrl("file:///android_asset/chapter-001.html");
                            System.err.println("Load Previous page");

                        } 
                        else 
                        {
                            findHeight = findHeight - protraitHeight;
                            mainWebView.scrollTo(0, findHeight);
                        }
                    }
                    System.err.println("After Height-->" + findHeight);
                }
            return true;
        }
    }

but i can't Display the last page of current html page path.now what to do.any solution please give.it's urgent. i get the content width properly and use the scrollTo method to display but i can't do it.after last page rest of some contain can't display.

Please saw me the any way.

Thank in advance..

like image 880
Zala Janaksinh Avatar asked Aug 18 '12 10:08

Zala Janaksinh


People also ask

How do I display HTML content in WebView?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken web view to show html content.

How can I get HTML content of URL open in Android WebView?

This can be achieved using below code. webview. setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { webview. loadUrl("javascript:window.

Is it possible to get data from HTML forms into Android while WebView?

Yes you can, you can use javascript to get webpage content. Then use the webview jsInterface to return the content to you java code.


1 Answers

Hi Friends Finally i got my question answer.i use the ScrollTo method to scroll the contain and Display next contain of current page.but problem is there webView Display all contain according device.so all time contain display is higher then this current value.so i use the Webview.getScale(); method to Display how much scale use by webview.according to this i use this method and get current contain of webview in and use Display page wise.its finally its work for me..

Name For CalenderOuthenticationDe

like image 108
Zala Janaksinh Avatar answered Nov 05 '22 13:11

Zala Janaksinh