Java Question "Type" Library Parameter Question

stevesuk

New Member
Licensed User
Longtime User
Hi,

Firstly, before I delve further, a question!

Can a List of "Type" records be created/updated back and forth between a library and B4A?

If yes, can anybody point me in the direction, or provide some sample code. of how it can be done.

Thanx.
 

agraham

Expert
Licensed User
Longtime User
A Basic4android List is a Java ArrayList and should be passable in both directions with no problem.

Accessing the Type instances contained in an ArrayList is a bit more tricky. A Type is a Java Class declared in the Basic4android generated code and the library will not know about that Class at compilation time. The best way of dealing with them is probably to declare the ArrayList to contain Objects and then use reflection to access the fields. If you pass a Type instance in an initializer for the library object you can extract and cache (for efficiency reasons) the Field objects for the Type Class and use them when needed. I guess you can assume what the field names are (though you could reflect for them if necessary) and as the Fields of a Type are not Public you will probably need to use getDeclaredField and setAccessible.

B4X:
Field f = TypeInstance.getDeclaredField("whatever");
f.setAccessible(true); // now save f to use in the future

If you are new to Reflection get a Java decompiler like JD-GUI | Java Decompiler and poke around in my Reflection library.
 
Top