Xamarin控件使用之ListView

listview单列多行的显示,以后再加多列多行的实例。

 [Activity(Label = "GraphicAll", LaunchMode = LaunchMode.SingleTop)]
public class GraphicMain : Activity//, IOnMenuTabClickListener
{ private ListView mListView;
private List<string> items = new List<string>(); string[] ItemName = { "投入产出", "成品率","能源日结" };
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState); // Create your application here
SetContentView(Resource.Layout.GraphicAll); mListView = FindViewById<ListView>(Resource.Id.listVGraphiMain);
for (int i = ; i < ItemName.Length; i++)
{
items.Add(ItemName[i]);
} ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);//多行一列的显示方法
mListView.Adapter = adapter;
mListView.ItemClick += mListView_ItemClick;//给没行添加点击事件
} void mListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
switch (e.Position)
{
case ://
{
var intent = new Intent(this, typeof(InOutActivity));//
StartActivity(intent);
}
break;
case ://
{
var intent1 = new Intent(this, typeof(productRateActivity));
StartActivity(intent1);
}
break;
case ://
{
var intent = new Intent(this, typeof(DayEnegryActivity));
StartActivity(intent);
}
break; default:
new AlertDialog.Builder(this)
.SetMessage("该功能还在开发中...")
.Show();
break;
}
} }
上一篇:设计模式(五)Builder Pattern建造者模式


下一篇:[译]LINT TO SQL 介绍(数据库查询) - Part.3