Xamarin控件使用之ListView
listview单列多行的显示,以后再加多列多行的实例。
1 [Activity(Label = "GraphicAll", LaunchMode = LaunchMode.SingleTop)] 2 public class GraphicMain : Activity//, IOnMenuTabClickListener 3 { 4 5 private ListView mListView; 6 private List<string> items = new List<string>(); 7 8 string[] ItemName = { "投入产出", "成品率","能源日结" }; 9 protected override void OnCreate(Bundle savedInstanceState) 10 { 11 base.OnCreate(savedInstanceState); 12 13 // Create your application here 14 SetContentView(Resource.Layout.GraphicAll); 15 16 mListView = FindViewById<ListView>(Resource.Id.listVGraphiMain); 17 for (int i = 0; i < ItemName.Length; i++) 18 { 19 items.Add(ItemName[i]); 20 } 21 22 ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);//多行一列的显示方法 23 mListView.Adapter = adapter; 24 mListView.ItemClick += mListView_ItemClick;//给没行添加点击事件 25 } 26 27 void mListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) 28 { 29 switch (e.Position) 30 { 31 case 0:// 32 { 33 var intent = new Intent(this, typeof(InOutActivity));// 34 StartActivity(intent); 35 } 36 break; 37 case 1:// 38 { 39 var intent1 = new Intent(this, typeof(productRateActivity)); 40 StartActivity(intent1); 41 } 42 break; 43 case 2:// 44 { 45 var intent = new Intent(this, typeof(DayEnegryActivity)); 46 StartActivity(intent); 47 } 48 break; 49 50 default: 51 new AlertDialog.Builder(this) 52 .SetMessage("该功能还在开发中...") 53 .Show(); 54 break; 55 } 56 } 57 58 }