Exemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.EditRecipe);

            recipeName        = FindViewById <EditText>(Resource.Id.edit_recipe_name);
            recipeIngredients = FindViewById <EditText>(Resource.Id.edit_recipe_ingredients);
            recipeDirections  = FindViewById <EditText>(Resource.Id.edit_recipe_directions);

            SQLiteOpenHelper recipeBookHelper = new RecipeBookSQLHelper(this);

            db = recipeBookHelper.WritableDatabase;

            CheckSharedPreferences();

            Button saveRecipe = FindViewById <Button>(Resource.Id.save_recipe);

            saveRecipe.Click += delegate
            {
                RecipeBookSQLHelper.InsertRecipe(db, recipeName.Text, recipeIngredients.Text, recipeDirections.Text);

                recipeName.Text        = String.Empty;
                recipeIngredients.Text = String.Empty;
                recipeDirections.Text  = String.Empty;
            };
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SQLiteOpenHelper recipeBookHelper = new RecipeBookSQLHelper(this);

            db = recipeBookHelper.ReadableDatabase;

            cursor = db.Query("RECIPE", new string[] { "_id, NAME" }, null, null, null, null, null);
            CursorAdapter recipes = new SimpleCursorAdapter(this, Android.Resource.Layout.SimpleListItem1, cursor, new string[] { "NAME" }, new int[] { Android.Resource.Id.Text1 }, 0);

            ListAdapter = recipes;

            ListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
            {
                Intent intent = new Intent(this, typeof(RecipeActivity));
                intent.PutExtra(RecipeActivity.EXTRA_RECIPE_NUM, e.Position);
                StartActivity(intent);
            };

            ListView.ItemLongClick += (object sender, AdapterView.ItemLongClickEventArgs e) =>
            {
                //Toast.MakeText(this, ListAdapter.GetItem(e.Position).ToString(), ToastLength.Short).Show();
                // create ingredient fragment so ingredients can be previewed

                FragmentTransaction ft   = FragmentManager.BeginTransaction();
                Fragment            prev = FragmentManager.FindFragmentByTag("dialog");

                if (prev != null)
                {
                    ft.Remove(prev);
                }
                ft.AddToBackStack(null);

                Bundle strings      = new Bundle();
                int    recipeNumber = e.Position;

                cursor = db.Query("RECIPE", new string[] { "NAME", "INGREDIENTS", "DIRECTIONS" }, "_id = ?", new string[] { (++recipeNumber).ToString() }, null, null, null);
                if (cursor.MoveToFirst())
                {
                    strings.PutString("RName", cursor.GetString(0));
                    strings.PutString("RIngredients", cursor.GetString(1));
                }

                IngredientsDialog newFragment = IngredientsDialog.NewInstance(strings);
                newFragment.Show(ft, "dialog");
            };
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Recipe);

            int recipeNumber = Intent.GetIntExtra(RecipeActivity.EXTRA_RECIPE_NUM, 0);

            try
            {
                SQLiteOpenHelper cookbookHelper = new RecipeBookSQLHelper(this);
                SQLiteDatabase   db             = cookbookHelper.ReadableDatabase;

                ICursor cursor = db.Query("RECIPE", new string[] { "NAME", "INGREDIENTS", "DIRECTIONS" }, "_id = ?", new string[] { (++recipeNumber).ToString() }, null, null, null);

                if (cursor.MoveToFirst())
                {
                    name        = cursor.GetString(0);
                    ingredients = cursor.GetString(1);
                    directions  = cursor.GetString(2);
                }
            }
            catch (SQLException e)
            {
                Toast.MakeText(this, "Cookbook unavailable", ToastLength.Short).Show();
            }

            TextView recipeName = FindViewById <TextView>(Resource.Id.recipe_name);

            recipeName.Text = name;

            TextView ingredientList = FindViewById <TextView>(Resource.Id.ingredient_list);

            ingredientList.Text = ingredients;

            TextView directionList = FindViewById <TextView>(Resource.Id.direction_list);

            directionList.Text = directions;

            ImageButton editButton = FindViewById <ImageButton>(Resource.Id.edit_recipe);

            editButton.Click += OpenRecipeForEditing;
        }