コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);

            SetContentView(Resource.Layout.MenuListView);

            // Add lunch menu button
            Button addMenuButton = FindViewById <Button> (Resource.Id.addMenu);

            addMenuButton.Click += delegate {
                addMenu();
            };

            ListView listView = FindViewById <ListView> (Resource.Id.lunchMenuList);

            List <LunchMenuListItem> menuItems = getMenuItems();
            LunchMenuAdapter         adapter   = new LunchMenuAdapter(this, menuItems);

            listView.Adapter = adapter;
        }
コード例 #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            View view = inflater.Inflate(Resource.Layout.SelectMenuDialog, container, false);

            // Select menu name (id) spinner
            Spinner menuSpinner = view.FindViewById <Spinner> (Resource.Id.selectMenuSpinner);
            // Apply menu items adapter from db
            var adapter = new LunchMenuAdapter(activity, getMenuItems());

            menuSpinner.Adapter  = adapter;
            menuSpinner.Selected = false;

            // Select optional inputs
            isOptionalSelected = false;
            Button optionalButton = view.FindViewById <Button> (Resource.Id.optionalButton);

            optionalButton.Click += delegate {
                isOptionalSelected = !isOptionalSelected;
                switchOptions(view);
            };

            // Lunch Calory Text with default value
            EditText caloryText = view.FindViewById <EditText> (Resource.Id.caloryText);

            caloryText.Text = DEFAULT_VALUE.ToString();
            // Lunch Cost Text with default value
            EditText costText = view.FindViewById <EditText> (Resource.Id.costText);

            costText.Text = DEFAULT_VALUE.ToString();

            // Confirm Today's Menu
            Button registerButton = view.FindViewById <Button> (Resource.Id.registerButton);

            registerButton.Click += delegate {
                int selectedPos  = menuSpinner.SelectedItemPosition;
                var selectedItem = adapter[selectedPos];
                // If optional values are set, use them values on log.
                float calory = selectedItem.calory;
                float cost   = selectedItem.cost;
                if (isOptionalSelected)
                {
                    float optionalCalory = float.Parse(caloryText.Text);
                    if (optionalCalory > 0)
                    {
                        calory = optionalCalory;
                    }

                    float optionalCost = float.Parse(costText.Text);
                    if (optionalCost > 0)
                    {
                        cost = optionalCost;
                    }
                }

                regsiterLunchMenu(selectedItem.id, selectedItem.name, calory, cost);
            };

            // Cancel
            Button cancelButton = view.FindViewById <Button> (Resource.Id.cancelButton);

            cancelButton.Click += delegate {
                this.Dismiss();
            };

            return(view);
        }