Quantcast

Reusing UI code in class libraries

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Reusing UI code in class libraries

andyjohnson0
I have some UI classes that I want to re-use across a number of projects. Normally I would put them in a class library to be referenced by the projects. However, they reference resources (mainly layouts and strings) and resources in class libraries are not (yet?) supported.

So I'm wondering what is best practice for this scenario?

One obvious approach is to put the classes in a class library and pass a Context reference plus all necessary integer resource values to instances at construction-time. This still requires the resources themselves to be duplicated across the non-library projects, but I could live with that if I could re-use the code.

Another thought: is it possible to load layouts from .net embedded xml resources?

I would appreciate any advice on this.

Andy
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reusing UI code in class libraries

Jonathan Pryor-2
On Oct 7, 2013, at 12:07 PM, andyjohnson0 <[hidden email]> wrote:
> However, they reference resources (mainly layouts and strings) and resources in class libraries are not (yet?) supported.

Android Resources within Class Libraries have been supported since Mono for Android 4.4:

        http://docs.xamarin.com/releases/android/mono_for_android_4/mono_for_android_4.4
> • Library Projects can now contain Android Resources.

Using them wasn't necessarily easy then (the default Library template didn't include any Resources), but it worked.

Recent versions of Xamarin Studio and Visual Studio should now include the Resources directory in the default Android Class Library template. (At least the VS 4.8.x add-in does...)

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reusing UI code in class libraries

andyjohnson0
Thanks Jon. It turned out I was using 4.3.something on the machine in question. I was so sure that it was up to date that I didn't check, and then I found old comments on SO complaining about lack of resource support in class libs which just re-enforced by belief that it still wasn't supported. I've updated to 4.8 and all is good.

Andy
Loading...