0

i have an xml layout file like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"  android:background="#262626">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="EXIT" />

 <ScrollView
        android:id="@+id/sv2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="10dp" android:background="#ffffff">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <WebView
                android:id="@+id/add_webView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:scrollbarStyle="insideOverlay"
                android:text="@string/desc" />

        </RelativeLayout>
    </ScrollView>
</LinearLayout>

i would like to load my Url in my app,and keep the button i have created above of my webView. Unfortunately, i m getting a webView in a new window on my device browser.

This is how i call the webView:

WebView add_webView = (WebView) dialog
                    .findViewById(R.id.add_webView);

            add_webView.loadUrl(MYLINK);

How can i get my webView into my app and not in the browser window? Thanks!!:)

menu_on_top
  • 2,613
  • 14
  • 44
  • 71
  • does your app declare the INTERNET permission in the manifest file? – atreat Apr 15 '13 at 18:25
  • yes. the page loads succesfully but not in my app but in the browsers window( outside of my app) – menu_on_top Apr 15 '13 at 18:26
  • looks to me like you are definitely using loadURL correctly.http://developer.android.com/reference/android/webkit/WebView.html#loadUrl(java.lang.String) – atreat Apr 15 '13 at 18:31
  • thats my problem...according to the documentation my way is right...but my webView starts in the browser window and not in my app...and i have been using a very simple site as www.google.com in order to test it – menu_on_top Apr 15 '13 at 18:34
  • Is there a reason you are calling findViewById on dialog and not the activity itself? When you debug is the WebView allocated before you try and load the URL? – atreat Apr 15 '13 at 18:37
  • yes,i want to have an action bar (or something similar)above of my webVIEW – menu_on_top Apr 15 '13 at 18:43
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28268/discussion-between-atreat-and-androidde) – atreat Apr 15 '13 at 18:44

1 Answers1

0

As i would like the webView in a dialog,the solution was to use the setWebClient()

AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Title here");
    WebView wv = new WebView(this);

    wv.loadUrl("http:\\www.google.com");

    wv.setWebViewClient(new WebViewClient()
    {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);

            return true;
        }
    });

    alert.setView(wv);
    alert.setNegativeButton("Close", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int id)
        {
        }
    });
    alert.show();
menu_on_top
  • 2,613
  • 14
  • 44
  • 71