I was stuck at this line:
insetsDirtyField = RecyclerView.LayoutParams.class.getDeclaredField("mInsetsDirty");
The .class
"keyword" in Java is equivalent to the typeof()
keyword in C#, so this is (kinda/sorta) like:
var insetsDirtyField = typeof(RecyclerView.LayoutParams).GetDeclaredField("mInsetsDirty");
Except it isn't, because typeof()
returns a System.Type
, which doesn't know anything about java.lang.Object
instances.
Instead, you should use Java.Lang.Class.FromType(Type)
to obtain a Java.Lang.Class
instance, which will then allow you to use Java Reflection:
var klass = Java.Lang.Class.FromType (typeof (RecyclerView.LayoutParams));
var insetsDirtyField = klass.GetDeclaredField("mInsetsDirty");