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
The binding references the source object. To set the data binding, use the following two members of the target class: The BindingContext property specifies the source object. The SetBinding method specifies the target property and source property.
If you have existing Java functionality that you do not want to convert to C#, you can reuse your existing Java libraries in Xamarin. Android applications via two techniques: Create a Java Bindings Library – Using this approach, you use Xamarin tools to generate C# wrappers around Java types.
Android Callable Wrappers (ACWs) are required whenever the Android runtime invokes managed code. These wrappers are required because there is no way to register classes with ART (the Android runtime) at runtime. (Specifically, the JNI DefineClass() function is not supported by the Android runtime.}
In code, two steps are required: The BindingContext property of the target object must be set to the source object, and the SetBinding method (often used in conjunction with the Binding class) must be called on the target object to bind a property of that object to a property of the source object.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With