码迷,mamicode.com
首页 > 其他好文 > 详细

Xamarin学习笔记 -ListVew

时间:2016-04-26 09:39:46      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:

1,ListView:纵向列表

2,需要数据适配器呈现

 

ArrayAdapter<T>

用来绑定一个数组,支持泛型操作

SimpleAdapter

用来绑定在axmll中定义的控件对应的数据,

单独item的axmll布局可以实现自定义的样式效果,数据内容的绑定

SimpleCursorAdapter

用来绑定游标得到的数据

BaseAdapter

通用的基础适配器

 

3,SimpleAdapter 适配器

    public class AppDataViewModel:MvxViewModel
    {
       
        public Dictionary<string, object> Channel = new Dictionary<string, object>();
        public string test { get; set; } = "我是个测试";
        public override void Start()
        {
            base.Start();

        }
        public AppDataViewModel()
        {
            Channel.Add("1号菜单", "");
            Channel.Add("2号菜单", "");
            Channel.Add("3号菜单", "");
        }
        

    }
AppDataViewModel avm
= new AppDataViewModel(); var list1 = new List<IDictionary<string, object>>(); foreach(var c in avm.Channel) { JavaDictionary<string, object> jd = new JavaDictionary<string, object>(); //注意这里需要的是JavaDictionary jd.Add("txt", c.Key); //字段key
         //jd.Add("xx",xx) list1.Add(jd); } sa
= new SimpleAdapter(this, list1, Resource.Layout.main_menuItem, //item的样式布局文件 new string[] { "txt" }, //对应的字段key new int[] { Resource.Id.main_menuItem_id }); //item样式布局文件中需要绑定的元素id,将会对应到数据的字段key var menu = (ListView)FindViewById(Resource.Id.menu); menu.Adapter = sa;

layout/main_menuItem.axml  

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="100dip">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#FFFFFFFF"
        android:layout_weight="1.0"
        android:gravity="center"
        android:textSize="22px"
        android:id="@+id/main_menuItem_id" />
</LinearLayout>

 技术分享

Xamarin学习笔记 -ListVew

标签:

原文地址:http://www.cnblogs.com/windbell2/p/5433682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!