Exemple #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.ProductsList);

            ReadXml ReadProducts = new ReadXml(this.Assets);

            List <Product> productsList = ReadProducts.ProductsFromXml();

            ListView productsListView;

            productsListView            = FindViewById <ListView>(Resource.Id.listView1);
            productsListView.Adapter    = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItemMultipleChoice, productsList);
            productsListView.ChoiceMode = ChoiceMode.Multiple;
            Button button = FindViewById <Button>(Resource.Id.buttonMatches);


            //BY CLICKING A BUTTON APP SETS ANOTHER LAYOUT AND DISPLAYS A LIST OF PRODUCTS
            button.Click += delegate
            {
                //list view for checked products
                ListView productsLstView = FindViewById <ListView>(Resource.Id.listView1);

                //list for checked products
                List <Product> checkedProductList = new List <Product>();

                //checking products
                for (int i = 0; i <= productsList.Count; i++)
                {
                    if (productsLstView.IsItemChecked(i))
                    {
                        string productName = productsLstView.GetItemAtPosition(i).ToString();

                        Product product = new Product(productName);

                        checkedProductList.Add(product);
                    }
                }

                // remember checked products
                SharingObjects.finalCheckedProductList = checkedProductList;

                //intent to another activity
                var recipeListActivity = new Intent(this, typeof(RecipeListActivity));
                StartActivity(recipeListActivity);
            };
        }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.RecipeDetails);

            string recipeName = SharingObjects.recipeDetails.Name;

            ReadXml xml = new ReadXml(this.Assets);

            Recipe recipe = xml.GetRecipeFromXmlByName(recipeName);

            string recipeDescription = recipe.Description;

            string recipeCookingTime = recipe.CookingTime;

            TextView nameView = FindViewById <TextView>(Resource.Id.nameView);

            nameView.Text = recipeName;

            TextView descriptionView = FindViewById <TextView>(Resource.Id.desciptionView);

            descriptionView.Text = recipeDescription;

            TextView cookingTimeView = FindViewById <TextView>(Resource.Id.cookingTimeView);

            cookingTimeView.Text = recipeCookingTime;

            ListView productsView = FindViewById <ListView>(Resource.Id.productsView);

            productsView.Adapter = new ArrayAdapter(this, Android.Resource.Layout.TestListItem, recipe.Ingridients);

            Button buttonToMenuActivity = FindViewById <Button>(Resource.Id.buttonToMenuActivity);

            buttonToMenuActivity.Click += delegate
            {
                var menuActivity = new Intent(this, typeof(MenuActivity));
                StartActivity(menuActivity);
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.RecipeList);

            ReadXml ReadRecipes = new ReadXml(this.Assets);

            List <Recipe> recipeList = ReadRecipes.RecipesFromXml();

            List <Recipe> matchedRecipes = new List <Recipe>();

            foreach (Recipe r in recipeList)
            {
                int numberOfCheckedProducts = SharingObjects.finalCheckedProductList.Count;
                int sk2 = r.Ingridients.Count;

                int matchedIngridients = 0;
                foreach (Product recipeProduct in r.Ingridients)
                {
                    foreach (Product p in SharingObjects.finalCheckedProductList)
                    {
                        if (recipeProduct.Equals(p))
                        {
                            matchedIngridients++;
                        }
                    }
                }
                if (matchedIngridients == r.Ingridients.Count())
                {
                    matchedRecipes.Add(r);
                }
            }

            //List view variable which is needed for old version
            ListView recipeListView;

            //creating a ListView within our products (old veersion)
            recipeListView            = FindViewById <ListView>(Resource.Id.listView2);
            recipeListView.Adapter    = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItemSingleChoice, matchedRecipes);
            recipeListView.ChoiceMode = ChoiceMode.Single;

            Button buttonGoToUoutput = FindViewById <Button>(Resource.Id.buttonGoToOutput);

            buttonGoToUoutput.Click += delegate
            {
                ListView recipesLstView = FindViewById <ListView>(Resource.Id.listView2);

                for (int i = 0; i < matchedRecipes.Count; i++)
                {
                    if (recipesLstView.IsItemChecked(i))
                    {
                        string recipeName = recipesLstView.GetItemAtPosition(i).ToString();

                        SharingObjects.recipeDetails = new Recipe(recipeName);

                        break;
                    }
                }
                var recipeDetailsActivity = new Intent(this, typeof(RecipeDetailsActivity));
                StartActivity(recipeDetailsActivity);
            };
        }