0

我有一个数组列表。我需要通过它,看看输入时是否有一个元素。这个怎么做?

DatabaseUtil dbUtil1 = new DatabaseUtil(this);
        dbUtil1.open();
        Boolean contain=false;
        Cursor cursor = dbUtil1.fetchAllElements();
        if (cursor != null) {
            while (cursor.moveToNext()) {
                Model s= new Model(cursor.getString(1),cursor.getString(2));


                if (list.contains(s)) //THIS DOES NOT WORK
                {
                    contain=true;
                }
                else 
                    {
                    list.add(get(cursor.getString(1),cursor.getString(2)));
                    }

            }
        }

        dbUtil1.close();    
4

1 回答 1

0

您的实例是一个新对象....将您创建的对象添加到 else 中,如下所示:

            Model s= new Model(cursor.getString(1),cursor.getString(2));


            if (list.contains(s)) //THIS DOES NOT WORK
            {
                contain=true;
            }
            else 
            {
                list.add(s);
            }
于 2012-07-12T13:50:54.837 回答