我试着做这个例子http://techdroid.kbeanie.com/2010/09/expandablelistview-on-android.html,但使用MonoDroid的,我的问题是使用的Java编程,但我哈瓦problemas来呼吁BaseExpandableListAdapter Abstracs方法的孩子名单,即时通讯,因为我需要的例子从列表中放置groupPosition和childPosition,那么我该如何解决这个问题?ExpandableListView单为Android
回答
创建ExpandableListAdapter
的问题是,这些方法要求您返回Java.Lnag.Object.
的类型我还没有能够让您的java示例正常工作。
但是,这里是使用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);
}
}
}
}
你会如何在片段中使用它? – MikeOscarEcho 2016-02-09 20:06:14
在4.2之前(如4.0.6)版本使用单声道的Android,它应该是这样的:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Collections.Generic;
namespace MonoAndroidApplication2
{
[Activity(Label = "Expandable List Activity", MainLauncher = true)]
public class Activity1 : ExpandableListActivity
{
IExpandableListAdapter mAdapter;
String NAME = "NAME";
String IS_EVEN = "IS_EVEN";
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
List< IDictionary <String , object >> groupData = new List< IDictionary < string , object >>();
List< IList<IDictionary< String, object>>> childData = new List < IList < IDictionary < string, object>>>();
for (int i = 0; i < 20; i++)
{
Dictionary< String, object > curGroupMap = new Dictionary < string , object >();
groupData.Add(curGroupMap);
curGroupMap.Add(NAME, "Group " + i);
curGroupMap.Add(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
List< IDictionary <String , object >> children = new List< IDictionary < string , object >>();
for (int j = 0; j < 15; j++)
{
Dictionary< String, object > curChildMap = new Dictionary < string , object >();
children.Add(curChildMap);
curChildMap.Add(NAME, "Child " + j);
curChildMap.Add(IS_EVEN, (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, IS_EVEN },
new int[] { Android.Resource.Id.Text1, Android.Resource.Id.Text2 },
childData,
Android. Resource. Layout.SimpleExpandableListItem2,
new String[] { NAME, IS_EVEN },
new int[] { Android.Resource .Id.Text1, Android.Resource.Id.Text2 }
);
SetListAdapter(mAdapter);
}
}
}
这段代码的任何感谢的创作,lanks。
它_could_可以这样; “更新为4.2.1”的答案也应该适用于4.0.6,因此应该优先考虑4.0.6,以尽量减少4.0.6和4.2.1之间的变化。 – jonp 2012-06-01 15:47:53
- 1. ANDROID - ExpandableListView
- 2. 3级ExpandableListView Android
- 3. Android中的ExpandableListView
- 4. Android - TableLayout to ExpandableListView
- 5. Android ExpandableListView GroupIndicator gravity
- 6. 如何将ExpandableListview左图标更改为其他人(android ExpandableListView)
- 7. ExpandableListView Mono for Android,ClickEvents
- 8. 的Android ExpandableListView错误
- 9. Android ExpandableListVIew使用BaseExpandableListAdapter
- 10. 用Android Swap扫描Android ExpandableListView
- 11. Android的 - 为子项ExpandableListView变化背景
- 12. Android ExpandableListView组位置始终为0
- 13. Expandablelistview中的奇怪行为 - Android
- 14. ExpandableListView为null
- 15. 如何将订单设置为Expandablelistview?
- 16. Android中的不同值ExpandableListView
- 17. Android ExpandableListView来自数据库
- 18. 延迟加载android ExpandableListView
- 19. Android ExpandableListView与SimpleCursorTreeAdapter不刷新
- 20. Android ExpandableListView onClickListener for Group行
- 21. Android ExpandableListView动态高度
- 22. Android的检测ChildClick在ExpandableListView
- 23. Android ExpandableListView - 寻找教程
- 24. ExpandableListView中的Android分隔符
- 25. 的Android expandablelistview使用凌空
- 26. expandableListView android标题背景
- 27. 在Android中展开ExpandableListView
- 28. Android - ExpandableListView实现可筛选
- 29. Android ExpandableListView滑动儿童
- 30. ExpandableListView上下文菜单
我不认为我很理解这个问题。你如何在java代码中做到这一点? – 2011-12-29 23:33:13