程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C# 使用 Xamarin開發應用--list+search

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

編輯:C#入門知識

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


[Activity(Label = "ServiceBooking")]
    public class ServiceBooking : Activity
    {
        private SearchView _searchView;
        private ListView _lv;
        private ArrayAdapter _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(Resource.Id.listView1);
            _adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, _products);
			_lv.Adapter = _adapter;

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

    }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved