[mono-android] sharing code between mono touch and mono for android

Dean Cleaver dean.cleaver at xceptionsoftware.com
Mon Jan 30 15:24:49 UTC 2012


Mine's a little strange to explain but I will try:

I've opted to use nibless in iPhone, and likewise I add controls in code on Android too. So I have a framework library for each OS that can "AddLabelAndText" which adds a label indented by x, y wide with a gap of x to a textbox that's z wide - I'm sure you get the idea. This framework also has inherited versions of views/activities as well as buttons etc to provide common functions.

In each device project I link to a common file - say "LoginScreen.cs". It will inherit from "BaseScreen", and each project will have a "BaseScreen.cs" inheriting from its respective view/activity in the framework above. In effect, this now means that all code in LoginScreen calls 2 different base frameworks depending on the device.

So LoginScreen has protected properties for all its labels and textboxes, buttons etc and are created in code. I've mapped common click events to both versions of the framework button classes, so LoginScreen has click events for the buttons that handle all the logic etc.

In reality, I do inherit from LoginScreen in each project also because some things just cannot be done the same way (badges for example seem to be impossible on Android) but 95% of the actual code is common to both.

Dino

From: monodroid-bounces at lists.ximian.com [mailto:monodroid-bounces at lists.ximian.com] On Behalf Of Wally McClure
Sent: Monday, January 30, 2012 8:59 AM
To: monodroid at lists.ximian.com; monotouch at lists.ximian.com
Subject: [mono-android] sharing code between mono touch and mono for android

I've been talking with Mark Bradley about sharing code between MT and MfA projects.  I'm curious what are the strategies that you are using to share code between the two platforms.  Any thoughts/advice are appreciated.  We've each got a way that we're doing.  I'm using separate projects and am linking files.  Mark is doing something a little different where he references the .dll directly in his MT and MfA projects.  I think both have pluses/minuses.  What are you doing?  Is there some macdaddy project type that we have missed that would allow us to share things easily?  Are we both missing something?

Wally
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monodroid/attachments/20120130/a40856e7/attachment-0001.html>


More information about the Monodroid mailing list