Android的列表视图多列 [英] Android Listview with multiple columns

查看:210
本文介绍了Android的列表视图多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个C#的Andr​​oid列表视图,支持多列。
我发现了一些code如何在这里做一个列表视图:
http://www.heikkitoivonen.net/blog/2009/02/15/multicolumn-listview-in-android/

I'm trying to do a C# Android Listview that supports multiple columns. I found some code how to do a Listview here: http://www.heikkitoivonen.net/blog/2009/02/15/multicolumn-listview-in-android/

然而,这就是Java code所以我把它转换成C#如下:

However this is Java code so I converted it to C# as follows:

        // 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抱怨说,第二个参数是不正确。据报道这种

The SimpleAdapter complains that the 2nd parameter is incorrect. It reports this

错误1 =

对于最佳重载方法匹配'Android.Widget.SimpleAdapter.SimpleAdapter(Android.Content.Context,System.Collections.Generic.IList>,整型,字符串[],INT [])'有一些无效参数

The best overloaded method match for 'Android.Widget.SimpleAdapter.SimpleAdapter(Android.Content.Context, System.Collections.Generic.IList>, int, string[], int[])' has some invalid arguments

错误2 =

参数2:无法从System.Collections.Generic.List>转换为System.Collections.Generic.IList>

Argument 2: cannot convert from 'System.Collections.Generic.List>' to 'System.Collections.Generic.IList>'

这是为什么?请你能不能帮我,我一直在使用谷歌,看是否有创建一个ListView(Android版)多列的方式研究,但找不到任何在C#,Java的只有code。

Why is this? Please could you help me as I have researched using google to see if there are ways of creating a Listview (for Android) with multiple columns but cannot find any in C#, only Java code.

谢谢,

安德鲁·阿什克罗夫特

推荐答案

您有MYLIST的定义和预期列表在Android不一致 SimpleAdapter

You have inconsistency between the definition of mylist and expected list in the Android SimpleAdapter

更改code以下;

         // 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;

如果您的活动实现了ListActivity比应更换行

If your activity implements ListActivity than you should replace the line

list.Adapter = mSchedule;

ListAdapter = mSchedule;

问候,

沙洛姆Keynan

这篇关于Android的列表视图多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆