Is there a way to define a webview in the layout xml rather than in the code.
And if so how? Or is it recommended that it's coded in to an activity?
Yes as above use the WebView tag:
<WebView android:id="@+id/webview"
android:layout_width="fill_parent" android:layout_height="50dip"/>
A sample application can be found here: http://www.androiddom.com/2011/04/creating-android-calculator-tutorial.html
The author creates a calculator that uses the WebView which is specified in the main.xml layout.
Yes, use the <WebView />
tag to do this in the xml layout.
and in your code type this :
WebView wv = (WebView)findViewById(R.id.webview);
wv.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
wv.loadUrl("your url here");