Loading a webview using Xamarin.android error no implicit refrence conversion from webview to views

EmyMa341EmyMa341 USMember ✭✭

Hello friends I have been working on this since hours, something is wrong. I am following this documentation (http://developer.xamarin.com/guides/android/user_interface/web_view/).

I am getting this error for simple loading a URL into a webview on this line of code ( web_view = FindViewById(Resource.Id.webview); )
Error 1 The type 'myplano_android.WebView' cannot be used as type parameter 'T' in the generic type or method 'Android.App.Activity.FindViewById(int)'. There is no implicit reference conversion from 'myplano_android.WebView' to 'Android.Views.View'. C:\Users\makhan.PLANO\documents\visual studio 2013\Projects\myplano-android\myplano-android\WebView.cs 29 24 myplano-android

This is my class code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Webkit;

namespace myplano_android
{

[Activity(Label = "WebView")]
public class WebView : Activity
{
     WebView web_view;

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

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

        web_view = FindViewById<WebView>(Resource.Id.webview);
       // web_view.Settings.JavaScriptEnabled = true;
       // web_view.LoadUrl("http://www.google.com");
    }
}

}

Finally After removing this error, I want to an HTTPS request, I already implemented this for iOS but I don't know much android, In iOS i know there are delegates to do stuff like webviewbegin loading. I need a list of delegates in android. These are delegates in IOS, Are the same in android or different ?

public override void LoadView()
{

    }

    public override void ViewDidUnload()
    {
        base.ViewDidUnload();

    }

    [Foundation.Export("webView:shouldStartLoadWithRequest:navigationType:")]
    public bool ShouldStartLoad(UIKit.UIWebView webView, Foundation.NSUrlRequest request, UIKit.UIWebViewNavigationType navigationType)
    {

    }

    [Foundation.Export("connection:willSendRequestForAuthenticationChallenge:")]
    public void WillSendRequestForAuthenticationChallenge(NSUrlConnection connection, NSUrlAuthenticationChallenge challenge)
    {

    }

    [Foundation.Export("connection:didReceiveResponse:")]
    public void DidReceivedResponse(NSUrlConnection connection, NSUrlResponse response)
    {

    }

    [Foundation.Export("webViewDidFinishLoad:")]
    public void LoadingFinished(UIWebView webView)

    {

    }

    [Foundation.Export("connection:LoadFailed:")]
    public void LoadFailed(UIKit.UIWebView webView,NSError error)
    {

    }

Answers

  • R.VR.V USMember

    add layout and put webview inside layout and give setcontentlayout(resource.Layout.LAYOUT_NAME);

    // Set our view from the "main" layout resource
    SetContentView(Resource.Layout.WebView); //Change layout relative or linear it works well

        web_view = FindViewById<WebView>(Resource.Id.webview);
       // web_view.Settings.JavaScriptEnabled = true;
       // web_view.LoadUrl("http://www.google.com");
    
Sign In or Register to comment.