多个循环没有给出所需的结果

时间:2015-06-11 12:01:08

标签: android

我正在研究一种方法,当我使用带有条件的单个循环时,它会检查if和else条件。但是当我添加多个具有条件的循环时,它只检查其他条件我不知道哪里有问题。请帮助我 这是我的代码

 public void compareArray() {
        ArrayList<Boolean> subset = new ArrayList<>();
for (int j = 0; j < (arrayBeef1.length); j++) {
            for (int i = 0; i < Items.size(); i++) {
                if ((arrayBeef1[j].equals(Items.get(i)))) {
                    subset.add(true);
                    break;
                }
            }
        }
        if (subset != null) {
            if (arrayBeef1.length == subset.size()) {
                Intent nextClass = new Intent();
                nextClass.setClass(AddItem.this, BeefRecipes.class);
                startActivity(nextClass);
                finish();
            } else {
                Toast.makeText(getApplicationContext(), "Un-Matched", Toast.LENGTH_LONG).show();
            }
        }
        for(int j = 0 ; j < (arrayBeef2.length) ; j++) {
            for (int i = 0; i < Items.size(); i++) {
                if ((arrayBeef2[j].equals(Items.get(i)))) {
                    subset.add(true);
                    break;
                }
            }
    }
            if (subset != null) {
        if (arrayBeef2.length == subset.size()) {
            Intent nextClass = new Intent();
            nextClass.setClass(AddItem.this, BeefRecipes.class);
            startActivity(nextClass);
            finish();
        } else {
            Toast.makeText(getApplicationContext(), "Un-Matched", Toast.LENGTH_LONG).show();
        }
    }

其中Item数组是动态数组,通过spinner和beefArray1填充,两个是

String[] arrayBeef1 = { "carrot","ginger",
            "onion","beef","unsalted butter"};
    String[] arrayBeef2 = { "garlic","olive oil", "onion",
            "Dijon mustard","beef","salt","carrot","rosemary"};

和Items arraList使用类似的项目生成 请帮助我用这个方法做什么

0 个答案:

没有答案