Xamarin学习笔记 -ListVew

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>

 

转载于:https://my.oschina.net/u/2528692/blog/666766

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值