首頁  >  文章  >  後端開發  >  C# 使用 Xamarin開發應用程式--list+search

C# 使用 Xamarin開發應用程式--list+search

黄舟
黄舟原創
2017-03-01 10:35:301389瀏覽

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 )!


#
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn