using System.Collections.Generic;
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
namespace App3
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
SimpleAdapter content;//定义适配器
IList<IDictionary<string, object>> data;//定义数据
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
ListView list = FindViewById<ListView>(Resource.Id.listView1);//绑定ListView
data = new List<IDictionary<string, object>>();//初始化数据
/*添加数据内容*/
for (int i = 0; i < 20; i++)
{
JavaDictionary<string, object> achievement = new JavaDictionary<string, object>();
achievement.Add("Name", i.ToString());
data.Add(achievement);
}
content = new SimpleAdapter(this, data, Android.Resource.Layout.SimpleListItem2, new string[] { "Name" }, new int[] { Android.Resource.Id.Text1 });//创建数据适配器
list.Adapter = content;//将适配器数据添加到ListView
}
}
}