Mono for Android by example: Working with list adapters

<p>This is the second post in a series on Mono for Android by Example. This time I'm going to take you on a tour around the listview in Android and how you can bind data to a listview. Please note that this post will not be as extensive as the <a href="" target="_blank">previous one on action bars</a>, this one is meant to show you the basics.</p><!--more--><p>At the end of this post you will know how you can create a new list activity with a list of items on it. You will also know a little bit about making lists perform on Android and what the options you have to extend lists.</p> <h2>Implementing the activity</h2> <p>When you want to display a list of items on Android, there's two routes you can go down. The first one is constructing an activity that is based on the ListActivity. Another method is to create a new ListView element in the layout file of your activity and attaching a list adapter to it. </p> <p>Both approaches are very similar. Except for the fact that the list activity approach uses a base class to get the layout for free, while the other approach asks you to place a ListView somewhere in the layout file for your activity.</p> <p>I'm only going to show you how you can create a list using the list activity approach. For this you will need a new activity, which contains the following lines of code:</p>

[Activity (Label = "Windesheim demo", MainLauncher = true)]
public class MainActivity : ListActivity
protected override void OnCreate (Bundle bundle)
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
this.ListAdapter = new PeopleListAdapter(this,Model.Items);

<p>When the activity is started, the OnCreate method is invoked and in that method a new list adapter is constructed and assigned to the ListAdapter property of the activity.</p> <p><strong>Note: </strong>If you're using a ListView in your layout file, you will have to execute FindViewById<ListView>(Resource.Id.MyListViewId) to find the list view and assign the Adapter property on that view instead of using the code above. The rest of this post is still the same whether your using the ListActivity base type or the ListView element in a layout file.</p> <h2>Implementing the list adapter</h2> <p>The list adapter in the previous section is the key to implementing a list activity on Android. The list adapter component transforms a list of items into a set of views that are displayed on the screen of the phone. There's a number of base classes you can use to implement a list adapter. </p> <p>Android provides a number of basic adapters that you can use to display simple types on screen, like strings, integers, doubles and booleans can be displayed using these adapters. The following adapters are available for simple display:</p> <ul> <li>ArrayAdapter</li> <li>ArrayAdapter<T></li> <li>SimpleAdapter</li></ul> <p>All of these accept a list of items, that are then displayed using a standard layout. The standard layout is very basic, it contains just one textview in which a string representation is showed. This means that when you have a complex model, you will not be able to display them using these adapters. </p> <p>In order to display more complex objects you will have to implement a list adapter based on the BaseAdapter class. Within your own list adapter you can then tell Android which layout it should use and how the data should be presented on screen. Below is the code that you need for building a simple list adapter.</p>

Orchard advanced topics: Insiders look at shapes and templates

Orchard is a CMS that has a lot of power in a very nimble package. It's only a couple of megabytes in size, but houses a huge amount of flexibility. Especially when you start working with shapes and templates. For me, this part of Orchard is the thing you need to understand properly to get full power out of it. In this post I'm going to show you what's going on inside Orchard when you ask for a piece of content and render it in one or more templates you defined in your theme or module <!-- more -->

What happens when you request a piece of content?