コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            var items = GetItems();

            _adapter = new UserAdapter(this, Resource.Layout.MainRow, items);

            _adapter.NameChanged += (sender, args) =>
            {
                Toast.MakeText(this, $"New name {args.NewName}", ToastLength.Short).Show();
            };

            _listView = FindViewById <ListView>(Resource.Id.lvItems);

            _listView.Adapter = _adapter;

            var addButton = FindViewById <Button>(Resource.Id.addButton);

            addButton.Click += (sender, e) =>
            {
                var text = FindViewById <EditText>(Resource.Id.itemEditText).Text;
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                _adapter.AddItem(new User(_number, text));

                _number++;
            };

            var retrieveButton = FindViewById <Button>(Resource.Id.retrieveButton);

            retrieveButton.Click += (sender, e) =>
            {
                Toast.MakeText(this, $"Items from Activity {_adapter.GetItems().Count()}", ToastLength.Short).Show();
            };
        }