Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 2.35 KB  |  hits: 61  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ExpandableListView Mono for Android
  2. using System;
  3. using Android.App;
  4. using Android.Content;
  5. using Android.Runtime;
  6. using Android.Views;
  7. using Android.Widget;
  8. using Android.OS;
  9. using System.Collections.Generic;
  10. namespace MonoAndroidApplication2
  11. {
  12.     [Activity(Label = "Expandable List Activity", MainLauncher = true )]
  13.     public class Activity1 : ExpandableListActivity
  14.     {
  15.         IExpandableListAdapter mAdapter;
  16.         String NAME = "NAME";
  17.         String IS_EVEN = "IS_EVEN";
  18.         protected override void OnCreate(Bundle bundle)
  19.         {
  20.             base.OnCreate(bundle);
  21.             List< IDictionary <String , object >> groupData = new List< IDictionary < string , object >>();
  22.             List< IList<IDictionary< String, object>>> childData = new List < IList < IDictionary < string, object>>>();
  23.             for ( int i = 0; i < 20; i++)
  24.             {
  25.                 Dictionary< String, object > curGroupMap = new Dictionary < string , object >();
  26.                 groupData.Add(curGroupMap);
  27.                 curGroupMap.Add(NAME, "Group " + i);
  28.                 curGroupMap.Add(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
  29.                 List< IDictionary <String , object >> children = new List< IDictionary < string , object >>();
  30.                 for ( int j = 0; j < 15; j++)
  31.                 {
  32.                     Dictionary< String, object > curChildMap = new Dictionary < string , object >();
  33.                     children.Add(curChildMap);
  34.                     curChildMap.Add(NAME, "Child " + j);
  35.                     curChildMap.Add(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
  36.                 }
  37.                 childData.Add(children);
  38.             }
  39.             // Set up our adapter
  40.             mAdapter = new SimpleExpandableListAdapter (
  41.                     this,
  42.                     groupData,
  43.                     Android.Resource.Layout.SimpleExpandableListItem1,
  44.                     new String[] { NAME, IS_EVEN },
  45.                     new int[] { Android.Resource.Id.Text1, Android.Resource.Id.Text2 },
  46.                     childData,
  47.                     Android. Resource. Layout.SimpleExpandableListItem2,
  48.                     new String[] { NAME, IS_EVEN },
  49.                     new int[] { Android.Resource .Id.Text1, Android.Resource.Id.Text2 }
  50.                     );
  51.             SetListAdapter(mAdapter);
  52.         }
  53.     }
  54. }