C# 使用 Xamarin开发应用--list+search

黄舟
发布: 2017-03-01 10:35:30
原创
1393 人浏览过

C# 使用 Xamarin开发应用--list+search

[Activity(Label = "ServiceBooking")]
    public class ServiceBooking : Activity
    {
        private SearchView _searchView;
        private ListView _lv;
        private ArrayAdapter<string> _adapter;
        private string[] _products;
        protected override void OnCreate(Bundle bundle)
		{
			base.OnCreate (bundle);
			SetContentView (Resource.Layout.ServiceBooking);
			// TODO :get from service
			_products = new []{"Dell Inspiron", "HTC One X", "HTC Wildfire S", "HTC Sense", "HTC Sensation XE",
				"iPhone 4S", "Samsung Galaxy Note 800",
				"Samsung Galaxy S3", "MacBook Air", "Mac Mini", "MacBook Pro"};

			_lv = FindViewById<ListView>(Resource.Id.listView1);
            _adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, _products);
			_lv.Adapter = _adapter;

            _searchView = FindViewById<SearchView>(Resource.Id.searchView1);
            _searchView.QueryTextChange += (sender, args) =>
            {
                _lv = FindViewById<ListView>(Resource.Id.listView1);
                _adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1,
                    _products.Where(p => p.ToLower()
                        .Contains(args.NewText.ToLower())).ToArray());
                _lv.Adapter = _adapter;
            };
		}

    }
登录后复制

 以上就是C# 使用 Xamarin开发应用--list+search的内容,更多相关内容请关注PHP中文网(www.php.cn)!


相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板