我正在尝试做一个支持多列的 C# Android Listview。 我在这里找到了一些如何执行 Listview 的代码: http://www.heikkitoivonen.net/blog/2009/02/15/multicolumn-listview-in-android/
然而,这是 Java 代码,所以我将其转换为 C#,如下所示:
// List view control
ListView list = (ListView) FindViewById(Resource.Id.mylist);
List<Dictionary<string, string>> mylist = new List<Dictionary<string, string>>();
Dictionary<string, string> map = new Dictionary<string, string>();
map.Add("Profit Centre", "Systems");
map.Add("Last Updated", "16/02/2012 15:34");
mylist.Add(map);
map = new Dictionary<string, string>();
map.Add("Profit Centre", "IDTS");
map.Add("Last Updated", "20/02/2012 10:26");
mylist.Add(map);
SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, Resource.Layout.list_item,new String[] {"Profit Centre", "Lasted Updated",}, new int[] { Resource.Id.columnA, Resource.Id.columnB});
list.Adapter = mSchedule;
SimpleAdapter 提示第二个参数不正确。它报告了这一点
错误 1 =
'Android.Widget.SimpleAdapter.SimpleAdapter(Android.Content.Context, System.Collections.Generic.IList>, int, string[], int[])' 的最佳重载方法匹配有一些无效参数
错误 2 =
参数 2:无法从“System.Collections.Generic.List>”转换为“System.Collections.Generic.IList>”
这是为什么?请帮助我,因为我使用谷歌进行了研究,看看是否有创建多列 ListView (适用于 Android)的方法,但在 C# 中找不到任何方法,只有 Java 代码。
谢谢,
安德鲁·阿什克罗夫特
最佳答案
您在 Android SimpleAdapter
中的 mylist 和预期列表的定义不一致
将您的代码更改为以下内容;
// List view control
ListView list = (ListView)FindViewById(Resource.Id.mylist);
IList<IDictionary<string, object>> mylist = new List<IDictionary<string, object>>();
IDictionary<string, object> map = new Dictionary<string, object>();
map.Add("Profit Centre", "Systems");
map.Add("Last Updated", "16/02/2012 15:34");
mylist.Add(map);
map = new Dictionary<string, object>()>;
map.Add("Profit Centre", "IDTS");
map.Add("Last Updated", "20/02/2012 10:26");
mylist.Add(map);
SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, Resource.Layout.list_item,new String[] {"Profit Centre", "Lasted Updated",}, new int[] { Resource.Id.columnA, Resource.Id.columnB});
ListAdapter = mSchedule;
如果您的 Activity 实现了 ListActivity,那么您应该替换该行
list.Adapter = mSchedule;
与
ListAdapter = mSchedule;
问候,
沙洛姆凯南
关于c# - 具有多列的Android Listview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9740478/