c# - 具有多列的Android Listview

标签 c# android monodevelop

我正在尝试做一个支持多列的 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/

相关文章:

C# Mono on mac - 使用代码编译并运行另一个项目

java - 如何将调用带有身份验证的Post请求的C#代码转换为Java?

android - 用 Espresso 点击不完全可见的 imageButton

c# - session 的 Azure WebJob ServiceBusTrigger

java - 如何在以 api 级别 15 为目标时对 android 中的项目 vector 进行排序?

android - 如何使用 Glide 使用 AdaptiveBitmap 加载 IconCompat

macos - F# 无法在 MonoDevelop 2.8 for Mac 上安装

c# - 无法使用 git 部署到 Azure

c# - 使用 Google 作为身份提供商,通过 Azure ACS 对 Restful 服务进行身份验证

c# - 格式错误的 JSONP 响应