Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Load URL from FirstActivity to WebPageActivity

$
0
0

How do I load a url from firstActivity to the webpageActivity?

Here is my code: FirstActivity

protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it

        var welcomeLabel = new TextView (this);
        var timetable = FindViewById<Button> (Resource.Id.timetablebtn);
        var labinduction = FindViewById<Button> (Resource.Id.labinductionbtn); 
        var scisnews = FindViewById<Button> (Resource.Id.scisnewsbtn);
        string scisnewsurl = "http://cis.ulster.ac.uk/news-a-events-mainmenu-70";

        timetable.Click += (sender, e) => {
            var TimetableActivityI = new Intent (this, typeof(TimetableActivity));
            StartActivity (TimetableActivityI); 
        };

        labinduction.Click += delegate {
            var LabInductionI = new Intent (this, typeof(WebPage));
            LabInductionI.PutExtra ("labsched", "google.com");
            this.StartActivity (LabInductionI);
        };

        //labinduction.Click += (sender, e) => {
        //  var LabInductionI = new Intent (this, typeof(LabInduction));
        //  StartActivity (LabInductionI);
        //};

        scisnews.Click += delegate {
            var ScisNewsI = new Intent (this, typeof(WebPage));
            ScisNewsI.PutExtra ("scisnews", scisnewsurl);
            this.StartActivity (ScisNewsI);
        };
    }

        public class HelloWebViewClient : WebViewClient
        {
            public override bool ShouldOverrideUrlLoading (WebView view, string url)
            {
            view.LoadUrl ("http://cis.ulster.ac.uk/news-a-events-mainmenu-70");
                return true;
            }
        }

    }

Code: WebPageActivity

public class WebPage : Activity { WebView web_view; string newsurl;

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        // Create your application here
        SetContentView (Resource.Layout.WebPageLO);

        web_view = FindViewById<WebView> (Resource.Id.webview);

        web_view.Settings.JavaScriptEnabled = true;
        web_view.Settings.BuiltInZoomControls = true;




        web_view.SetWebViewClient (new HelloWebViewClient ());



    }
}


public class HelloWebViewClient : WebViewClient
{
    public override bool ShouldOverrideUrlLoading (WebView view, string url)
    {
        view.LoadUrl ("http://cis.ulster.ac.uk/news-a-events-mainmenu-70");
        return true;
    }
}


public override bool OnKeyDown (Android.Views.Keycode keyCode, Android.Views.KeyEvent e)
{
    if (keyCode == Keycode.Back && web_view.CanGoBack ()) 
    {
        web_view.GoBack ();
        return true;
    }

    return base.OnKeyDown (keyCode, e);
}

}


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>