Android 向列表中添加标题
在Xamarin中,我编写了如下列表:Android 向列表中添加标题,android,list,header,xamarin,listadapter,Android,List,Header,Xamarin,Listadapter,在Xamarin中,我编写了如下列表: protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); items = new List<Tuple<string, string>>(); //Header displaying Locations items.Add(new Tuple<string,string>("Fiji", "A nic
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
items = new List<Tuple<string, string>>();
//Header displaying Locations
items.Add(new Tuple<string,string>("Fiji", "A nice beach"));
items.Add(new Tuple<string,string>("Beijing", "AKA Shanghai"));
//Header displaying plants
items.Add(new Tuple<string,string>("Seedlings", "Tiny plants"));
items.Add(new Tuple<string,string>("Plants", "Green plants"));
ListAdapter = new List_Adapter(this, items);
}
protectedoverride void OnCreate(捆绑包)
{
base.OnCreate(bundle);
项目=新列表();
//标题显示位置
添加(新元组(“斐济”,“美丽的海滩”);
添加(新元组(“北京”、“又名上海”);
//标题显示植物
添加(新元组(“幼苗”、“小植物”);
添加(新元组(“植物”、“绿色植物”);
ListAdapter=新列表\适配器(此,项);
}
此列表显示正确
我的问题是:如何将标题添加到此列表
提前感谢.addHeaderView(查看);
<listView>.addHeaderView(View);
您可以拨打
listView.addHeaderView(...);
在listview实例上
编辑:
在将适配器设置为listView之前,应该调用listView.addHeaderView(…)\u。
例如:
View v = // inflate here the header view
listView.addHeaderView(v);
listView.setAdapter(/* you adapter instance */);
你能解释一下在上面的代码中在哪里写这个吗?我不知道如何膨胀标题视图。你能写一些快速的代码来处理我在OP中的代码吗?另外,我没有使用listView对象,我使用的是List();那么在哪里使用listAdapter呢?您不需要将其连接到listview吗?