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>