Ackman
Ackman

Reputation: 1592

Webview to display local HTML pages

Text within my textview within my fragment has a few links. I need to display them in a webview. The links point to a few webpages in my assets folder. How do go about it?

Upvotes: 0

Views: 88

Answers (2)

ikhsanudinhakim
ikhsanudinhakim

Reputation: 1634

Just load your web asset from your code.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    //....

        Webview wv = (WebView) layout. findViewById(R.id.webview);  
        wv.loadUrl("file:///android_asset/web.html");  

    return layout;
}

Upvotes: 1

KishuDroid
KishuDroid

Reputation: 5451

Have a new Activity named as WebviewActivity and put below code in it's java file:

public class WebviewActivity extends Activity { 
  WebView webview; 
        @Override  
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);
            setContentView(R.layout.webview);  

            webview= (WebView) findViewById(R.id.webView1);  
            webview.loadUrl("file:///android_asset/your file_name.html"); 
        }  
    }

Hope it will help you.

Upvotes: 1

Related Questions