ListView的SimpleAdapter使用

以下内容全部或部分转自或参考于网络。

 Xamarin中必须使用JavaDictionary,而不能用Dictionary。

            var mp3list = new List< IDictionary<string , object>>();
            foreach (var infos in mp3Infos)
            {
                Mp3Info mp3Info = (Mp3Info )infos;
                var map = new JavaDictionary< string, object >();

                map.Add( "title", mp3Info.Title);
                map.Add( "Artist", mp3Info.Artist);
                map.Add( "duration", mp3Info.Duration.ToString());
                map.Add( "size", mp3Info.Size.ToString());
                map.Add( "url", mp3Info.Url);

                mp3list.Add(map);
            }
            SimpleAdapter adapter = new SimpleAdapter( this, mp3list, Resource .Layout.music_list_item_layout,
                    new String [] { "title", "Artist", "duration" },
                    new int [] { Resource. Id.music_title, Resource .Id.music_Artist, Resource.Id .music_duration });
            lvMp3Info.Adapter = adapter;

 

上一篇:【Flutter 2-11】Flutter手把手教程UI布局和Widget——列表ListView


下一篇:ListView的用法