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.
Thanks for the blog + code.
ReplyDeleteFor 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.
This comment has been removed by the author.
ReplyDeleteKevin, 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?
ReplyDeleteThanks, I can provide an email if that would be easier.
Hi,
ReplyDeleteUnder was licence are your MvvmCross.DeapExtensions published?
Really great, I have started to port my WP8 Project to Xamarin and this code is really neccesary to implement the longlistselector in Android, Thanks a lot.
ReplyDelete