简体   繁体   中英

Xamarin.Android binding Call java Object method

I created java binding library via visual studio extension called Xamarin.GradleBinding. I added ru.rambler.android:swipe-layout:1.0.14 package and while using its SwipeLayout , it all works well. But unfortunately it did not created corresponding C# classes or anything like that. I tried adding package manually but still nothing.

I checked the source on GitHub . SwipeLayout has a public void method reset() without parameters:

public void reset()

I try to call this method from c# with JNIEnv .

IntPtr type = JNIEnv.FindClass("ru/rambler/libs/swipe_layout/SwipeLayout");
IntPtr method = JNIEnv.GetMethodID(type, "reset", "()V");
try
{
    JNIEnv.CallObjectMethod(_swiper.Handle, method);
}
catch (Exception ex)
{
    var s = ex.Message;
}

Type and method are successfully found but calling

JNIEnv.CallObjectMethod(_swiper.Handle, method);

This method crashes the app, it does not even goes into catch block.

Tt must be cause of the _swiper.Handle first parameter. _swiper field is of type ViewGroup since SwipeLayout is derived from ViewGroup . I can't find how to get the pointer of the view to pass that method.

while debugging, when I investigate the _swiper , it seems to be the correct instance of SwipeLayout

在此输入图像描述

I have done a rewrite of the control to C# with Xamarin.Android . It is available here on my GitHub , but I haven't had time to test it yet, so it might have bugs.

But you can try it and potentially fix the bugs I have missed during the rewrite using the original .java source code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM