Sunday, February 3, 2013

MvvmCross.DeapExtensions

Stuart Lodge suggested I start a separate library of extensions for the excellent MvvmCross framework. Meet MvvmCross.DeapExtensions.  The first addition is a grouped list view. Those familiar with the UITableView Section in UITableView on iOS will know exactly what I'm talking about. Its essentially a list with group headers separating items that belong together.

My model consists of profiles and each profile has a list of devices that belongs to it. Binding the BindableGroupListView to the list of profiles automatically gives us the result we after.



Here is my Activity with the the grouped list declared


The important part is the MvxBind which binds the ListView to the SearchedProfiles property in my ViewModel.



The Item and Group Template are regular Android Layouts containing TextViews. These TextViews are bound using MvvmCross directly to there respective model objects. So list item_profile was bound to the ProfileName property on Profile and listitem_device which has 2 TextViews was bound to Device and its corresponding propertys.

BindableGroupListView works by assuming the list of items you bind to it are groups and that these groups which are are enumerable contain the items you wish to see in the group.


Lastly, notice how I also declare the ItemClick to DeviceSelected in the bind command. DeviceSelected is an ICommand declared in the ViewModel. DeviceSelected gets the Device selected and navigates to another Activity. Right now clicks are ignored on the groups. I've added GroupClick to support click handling on the group items.

4 comments:

Hugo Logmans said...

Thanks for the blog + code.

For others trying this, some tips:
- Link this project in your own solution
- Derive your setup from the abstract setup class of DeapExtensions
- Copy one line from the Attributes XML file to your own Android project xml file.
- Make sure your group-level derives from IEnumerable. You can also just implement IEnumrator and fill in GetEnumerator to use some other property of your group class.

This will help you speedup using the code.

Ha Doan Manh said...
This comment has been removed by the author.
MErickson said...

Kevin, thanks for the blog entry, this is proving very useful for my current project. I am however a little confused on exactly what the full ViewModel should look like with your example. Any chance you could post the full viewmodel for this example?

Thanks, I can provide an email if that would be easier.

John Cashman said...

Hi,

Under was licence are your MvvmCross.DeapExtensions published?