【IT专家】Xamarin.Android之Spinner的简单探讨

【IT专家】Xamarin.Android之Spinner的简单探讨

2023年6月27日发(作者:)

本文由我司收集整编,推荐下载,如有疑问,请与我司联系d之Spinner的简单探讨

2016/04/23 669 一、前言今天用了一下Spinner这个控件,主要是结合官网的例子来用的,不过官网的是把数据写在中的,

 某种程度上,不是很符合我们需要的,比较多的应该都是从数据库读出来,绑定上去的。下面是官网的例子:

 n/guides/android/user_interface/spinner/

 二、来个简单的Demo新建一个类

  1 public class MyType 2 { 3 public int TypeId { get; set; } 4 5 public string

TypeName { get; set; } 6 7 public override string ToString() 8 { 9 return TypeId + “-” +

TypeName;10 }11 }

 再来点数据

  1 public static class DB 2 { 3 public static List MyType Types { get; private set; } 4

5 static DB() 6 { 7 Types = new List MyType (); 8 (new MyType { TypeId = 1,

TypeName = “type1” }); 9 (new MyType { TypeId = 2, TypeName =

“type2” });10 (new MyType { TypeId = 3, TypeName = “type3” });11

(new MyType { TypeId = 4, TypeName = “type4” });12 }13 }

 最后写个Adapter,我们自定义的Adapter都需要继承BaseAdapter

  1 public class MyTypeAdapter : BaseAdapter MyType 2 { 3 private readonly

Activity _context; 4 private readonly IList MyType _types; 5 6 public

MyTypeAdapter(Activity context, IList MyType types) 7 { 8 this._context = context; 9

this._types = types;10 }11 12 public override MyType this[int position]13 {14 get15 {16

return this._types[position];17 }18 }19 20 public override int Count21 {22 get23 {24

return this._;25 }26 }27 28 public override long GetItemId(int position)29 {30

return position;31 }32 33 public override View GetView(int position, View convertView,

ViewGroup parent)34 {35 View view = convertView;36 if (view == null)37 {38 view =

this._e(ListItem1,

发布者:admin,转转请注明出处:http://www.yc00.com/news/1687841272a49928.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信