2012-03-16 45 views
1

我想要做一個支持多列的C#Android Listview。 我發現了一些代碼是如何在這裏做一個列表視圖: http://www.heikkitoivonen.net/blog/2009/02/15/multicolumn-listview-in-android/有多列的Android Listview

然而,這是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抱怨說,第二個參數是不正確。它報告此

ERROR 1 =

關於「Android.Widget.SimpleAdapter.SimpleAdapter最好重載的方法匹配(Android.Content.Context,System.Collections.Generic.IList>,整型,字符串[], INT [])」具有一些無效參數

ERROR 2 =

參數2:不能從轉換 'System.Collections.Generic.List>' 到 'System.Collections.Generic.IList>'

這是爲什麼?請你能幫助我,因爲我研究過使用谷歌來查看是否有方法創建一個Listview(Android版)多列,但在C#中找不到任何東西,只有Java代碼。

感謝,

安德魯·阿什克羅夫特

+0

您正在使用C#爲Android開發板的pment? – alykhalid 2012-03-16 15:56:16

+0

是的,我正在使用MonoDevelop在C#中進行Android開發代碼 – coolandy28 2012-03-16 16:29:27

回答

1

你有MYLIST的定義和預期列表之間的不一致在Android SimpleAdapter

更改您的代碼如下;

  // 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應該比你有

ListAdapter = mSchedule; 

問候代替線

list.Adapter = mSchedule; 

沙洛姆Keynan