Forum Xamarin.Forms

Custom Renderer: Read view from layout

MaruMaru DEMember ✭✭

Hi!

I have an Android example I want to put into Xamarin.Forms:

<com.nativeandroidproject.view
  android:id="@+id/widget"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" />

NativeAndroidView widget = (NativeAndroidView) findViewById(R.id.widget);

The problem is that I can't create an object from that NativeAndroidViewinside of my custom renderer and pass it to SetNativeView(), the API from the NativeAndroidViewisn't supporting this. So I was wondering how I can put this together in Forms.

Tagged:

Best Answer

Answers

  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    You need to create the view in the usual Android way in the renderer.

    So instead of finding it by id, you should use

    NativeAndroidView control = (NativeAndroidView)LayoutInflater.From(Forms.Context).Inflate(Resource.Layout.filename, null, false);
    
  • MaruMaru DEMember ✭✭

    @AdamMeaney Thanks for the hint!
    Is filename in Resource.Layout.filename a native Android layout? Can you maybe make a short/simple example?

Sign In or Register to comment.