适用于Android的ExpandableListView Mono

ark*_*tal 1 c# listview expandablelistview xamarin.android

我试图做这个例子http://techdroid.kbeanie.com/2010/09/expandablelistview-on-android.html,但是使用monodroid,我的问题是我习惯用java编程但是我hava问题给孩子打电话在BaseExpandableListAdapter Abstracs方法上列出,因为我需要例如从列表中放入groupPosition和childPosition,所以我该如何解决这个问题呢?

sta*_*ith 6

创建一个问题ExpandableListAdapter的方法是,这些方法要求您返回Java.Lnag.Object.我无法让您的Java示例工作的类型.

但是这里有一个使用a ExpandableListView而不是定义自己ExpandableListAdapter而不仅仅是使用SimpleExpandableListAdapter类的例子.

此示例将使您能够使用ExpandableListView它,但它不会为您提供附加的灵活性BaseExpandableListAdapter.

using System;
using System.Collections.Generic;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace Scratch.ExpandableListActivity
{
    [Activity (Label = "Scratch.ExpandableListActivity", MainLauncher = true)]
    public class Activity1 : Android.App.ExpandableListActivity
    {
        IExpandableListAdapter mAdapter;
        const string Name = "NAME";
        const string IsEven = "IS_EVEN";

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            using (var groupData = new JavaList<IDictionary<string, object>> ())
            using (var childData = new JavaList<IList<IDictionary<string, object>>> ()) {
                for (int i = 0; i < 20; i++) {
                    using (var curGroupMap = new JavaDictionary<string, object>()) {
                        groupData.Add(curGroupMap);
                        curGroupMap.Add(Name, "Group " + i);
                        curGroupMap.Add(IsEven, (i % 2 == 0) ? "This group is even" : "This group is odd");
                        using (var children = new JavaList<IDictionary<string, object>> ()) {
                            for ( int j = 0; j < 15; j++) {
                                using (var curChildMap = new JavaDictionary<string, object> ()) {
                                    children.Add(curChildMap);
                                    curChildMap.Add(Name, "Child " + j);
                                    curChildMap.Add(IsEven, (j % 2 == 0) ? "This child is even" : "This child is odd");
                                }
                            }
                            childData.Add(children);
                        }
                    }
                }
                // Set up our adapter
                mAdapter = new SimpleExpandableListAdapter (
                        this,
                        groupData,
                        Android.Resource.Layout.SimpleExpandableListItem1,
                        new string[] { Name, IsEven},
                        new int[] { Android.Resource.Id.Text1, Android.Resource.Id.Text2 },
                        childData,
                        Android.Resource.Layout.SimpleExpandableListItem2,
                        new string[] { Name, IsEven },
                        new int[] { Android.Resource.Id.Text1, Android.Resource.Id.Text2 }
                        );
                SetListAdapter(mAdapter);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)