Пример #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.ManageFeed);

            var feedCategories = new DataAccess.CategoryRepository().GetAllCategories().ToList();

            var txtName = FindViewById <EditText> (Resource.Id.ManageFeed_FeedName_EditText);
            var txtUrl  = FindViewById <EditText>(Resource.Id.ManageFeed_Url_EditText);

            var lvCategory = FindViewById <ListView>(Resource.Id.ManageFeed_FeedCategories_ListView);

            lvCategory.ChoiceMode = ChoiceMode.Single;
            lvCategory.Adapter    = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItemSingleChoice, feedCategories.Select(c => c.Name).ToList());

            if (feedCategories.Count > 0)
            {
                lvCategory.SetSelection(0);
            }

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

            btnSave.Click += delegate
            {
                var feedRepo = new DataAccess.FeedRepository();
                feedRepo.Save(new DataAccess.Feed()
                {
                    Name = txtName.Text, Url = txtUrl.Text, CategoryId = lvCategory.SelectedItemPosition > -1 ? feedCategories[lvCategory.SelectedItemPosition].Id : 0
                });

                Toast.MakeText(this, "Feed saved", ToastLength.Short).Show();
                Finish();
            };
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.ManageFeed);

            var feedCategories = new DataAccess.CategoryRepository().GetAllCategories().ToList();

            var txtName = FindViewById<EditText> (Resource.Id.ManageFeed_FeedName_EditText);
            var txtUrl = FindViewById<EditText>(Resource.Id.ManageFeed_Url_EditText);

            var lvCategory = FindViewById<ListView>(Resource.Id.ManageFeed_FeedCategories_ListView);
            lvCategory.ChoiceMode = ChoiceMode.Single;
            lvCategory.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItemSingleChoice, feedCategories.Select(c => c.Name).ToList());

            if (feedCategories.Count > 0)
                lvCategory.SetSelection(0);

            var btnSave = FindViewById<Button>(Resource.Id.ManageFeed_Save_Button);
            btnSave.Click += delegate
            {
                var feedRepo = new DataAccess.FeedRepository();
                feedRepo.Save(new DataAccess.Feed(){ Name = txtName.Text, Url = txtUrl.Text, CategoryId = lvCategory.SelectedItemPosition > -1 ? feedCategories[lvCategory.SelectedItemPosition].Id : 0});

                Toast.MakeText(this,"Feed saved",ToastLength.Short).Show();
                Finish();
            };
        }