我正在尝试做这个例子 http://techdroid.kbeanie.com/2010/09/expandablelistview-on-android.html ,但是使用 monodroid,我的问题是我以前用 java 编程但是我有问题调用 BaseExpandableListAdapter Abstracs 方法上的子列表,因为我需要例如从列表中放置 groupPosition 和 childPosition,所以我怎么能解决这个问题?
最佳答案
创建 ExpandableListAdapter
的问题在于这些方法要求您返回 Java.Lnag.Object 的类型。
我无法获得您的 java 示例上类。
但这里是一个使用 ExpandableListView
的示例,没有定义您自己的 ExpandableListAdapter
而只是使用 SimpleExpandableListAdapter
类。
此示例将使您能够使用 ExpandableListView
,但它不会为您提供 BaseExpandableListAdapter
带来的额外灵 active 。
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);
}
}
}
}
关于c# - 适用于 Android 的 ExpandableListView Mono,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8674628/