lundi 25 février 2019

(ANDROID Is it possible to insert to sqlite database after nested if statements returns true?

I am supposed to check the aller(arraylist) if it contains the allergies and check listview onitemclick if the (texts)item name matches the current food in the database. If it returns true then the user would not be able to insert that food. However, there are other foods in the database that doesn't have any relations to the allergies. How do I insert the food to the database after all the nested if statements finish? *SOME IF's ARE STILL EMPTY BECAUSE THERE IS STILL NO FOOD FOR THE SPECIFIC ALLERGY

 if (bmi1 < 18.5){
                if(caltotal<limit){
                    if(aller.contains("Milk")){
                        if(texts.equals("Milk")){
                            all();
                        }
                    }if(aller.contains("Cheese")){
                        if(texts.equals("Cheese")){
                            all();
                        }
                    }if(aller.contains("Butter")){

                    }if(aller.contains("Nuts")){

                    }if(aller.contains("Shrimp")){
                        if(texts.equals("Boiled Shrimp")){
                            all();
                        }
                    }if(aller.contains("Squid")){

                    }if(aller.contains("Crab")){

                    }if(aller.contains("Lobster")){

                    }if(aller.contains("Chocolate")){

                    }if(aller.contains("Coconut")){

                    }if(aller.contains("Chicken")){
                        if(texts.equals("Chicken Adobo")||(texts.equals("Chicken Burger")||(texts.equals("Chicken Wing")))){
                            all();
                        }
                    }if(aller.contains("Soy")){

                    }if(aller.contains("Eggs")){
                        if(texts.equals("Fried Egg")||(texts.equals("Egg (Over easy)")||(texts.equals("Egg Scrambled")||(texts.equals("Omelette"))))){
                            all();
                        }
                    }if(aller.contains("Pork")){
                        if(texts.equals("Bacon")||(texts.equals("Sausage")||(texts.equals("Pork Adobo")||(texts.equals("Pork Chop")
                                ||(texts.equals("Pork Longganisa")))))){
                            all();
                        }
                    }if(aller.contains("Beef")){
                        if(texts.equals("Beef Tapa")||(texts.equals("Bulalo")||(texts.equals("Meatloaf")||(texts.equals("Corned Beef")||
                                (texts.equals("Beef Tapa")||(texts.equals("Burger")||(texts.equals("Beef Caldereta"))||(texts.equals("Chili"))
                                        ||(texts.equals("Chili Dog"))||(texts.equals("Hotdog"))||(texts.equals("Steak"))||(texts.equals("Luncheon Meat"))
                                        ||(texts.equals("Longganisa")))))))){
                            all();
                        }
                    }else{
                        insertFood(type1, name1, grams, fat1, cal1, carbs1, protein1, mtype, date);
                        Toast.makeText(getActivity(), "Food has been Added!", Toast.LENGTH_SHORT).show();
                    }
public void all(){
    AlertDialog.Builder exit = new AlertDialog.Builder(getActivity());
    exit.setMessage("You are allergic to this!");
    exit.setCancelable(false);
    exit.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    AlertDialog alertDialog = exit.create();
    alertDialog.show();
}

Aucun commentaire:

Enregistrer un commentaire