Monthly Archives: November 2014

Structuring your Android activities

MVVM, Technical stuff, Work, Xamarin, XAML

In Android development, what XAML coders call “code behind” is stored in a class deriving from Activity. This is where you will handle the UI events, prepare the view, etc. Just like in XAML, the code you put there is less testable and less shareable but for view code, this is the place to do it. Of course if you use MVVM Light (or another MVVM approach), you reduce the amount of view code and some of the issues go away.

When you come from XAML, you notice how pampered we are by Microsoft. For example, if I add a UI element in the XAML and give it a name as shown below, the IDE will automatically generate a field in the code behind, so that I can interact with this element, for example by handling some events. This is super convenient. Of course if you don’t give a name to the element, no field is generated, and you cannot interact with the element (which is OK for most of the elements on the UI). You might wonder where the field gets generated, in fact it is hidden. To find it, you will need to dig a little.

Read the rest of this entry »