DasBoot
DasBoot

Reputation: 707

simplest way to load android webview

what is the simplest way to load android webview?

I have already specified webview in the activity layout, how can i load a website on it while running the emulator. I have had many problems with resources not identified and the main_activity.out.xml files have been giving me troubles. A simple webview to load a webpage would be nice.

...

<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" />

Upvotes: 1

Views: 1516

Answers (3)

K_Anas
K_Anas

Reputation: 31466

You are getting main_activity.out.xml because you are trying to compile Xml files (main_activity.out.xml have the focus and you clicked run). In general if this error happens you have to

  1. Delete the xxx.out.xml
  2. Open any .java file in src/ by double click in the file so it has focus and the cursor is in there
  3. Run your project and everything should be OK now

to load WebView you have to declare your webview component in your xml

<WebView
    android:id="@+id/myWebView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" /> 

and then in your activity in onCreate() method call

// get reference to your view
WebView webview = (WebView)findViewById(R.id.myWebView);
// load your WebView content
webview.loadUrl("http://google.com/");

Upvotes: 3

Stefano Ortisi
Stefano Ortisi

Reputation: 5326

main_activity.out.xml has been created maybe beacuse you pressed the run button on Eclipse while your main_activity.xml was opened. Eclipse tryed to compile your xml and not your application.

To do that right, try to select the reference of your application inside the project explorer on the left and then click the Run button.

In order to manage at best the webview in your android project, just read the documentation:

http://developer.android.com/guide/webapps/webview.html

Upvotes: 0

fklappan
fklappan

Reputation: 3259

Simplest way?

Get access to WebView via

WebView webview = (WebView)findViewById(R.id.webView1);
webview.loadUrl("http://stackoverflow.com/");

Greets Flo

Upvotes: 0

Related Questions