我正在检查,以便将我最喜欢的Promotions对象放入数组中。 我尝试这样做(来自我的PromotionsBDD类,它控制我的SQLite数据库中的表格促销):
public ArrayList<Promotion> getListPromotionsFavorites()
{
String[] columns = new String[] {"ID", "RATING", "TITLE", "COMPANY_ID","AVAILABLEDATE", "DESCRIPTION", "SETONFAVORITE"};
Cursor objCursor = bdd.query(TABLE_PROMOTIONS, columns,null,null,null,null,null,null);//requete de récupération de la liste
int id = objCursor.getColumnIndex("ID");
int rating = objCursor.getColumnIndex("RATING");
int title = objCursor.getColumnIndex("TITLE");
int companyid = objCursor.getColumnIndex("COMPANY_ID");
int availabledate = objCursor.getColumnIndex("AVAILABLEDATE");
int description = objCursor.getColumnIndex("DESCRIPTION");
int setonfavorite = objCursor.getColumnIndex("SETONFAVORITE");
ArrayList<Promotion> promoFavoriteArray = new ArrayList<Promotion>();
objCursor.moveToFirst();// position sur la première ligne
if (objCursor != null)
{
if (objCursor.isFirst())
{
int i = 0;
do
{
String resultsetonfavorite = objCursor.getString(setonfavorite);
if (resultsetonfavorite.equals("true"))
{
i++;
String resultid = objCursor.getString(id);
String resultrating = objCursor.getString(rating);
String resultitle = objCursor.getString(title);
int resultcompanyid = objCursor.getInt(companyid);
String resultavailbledate = objCursor.getString(availabledate);
String resultdescription = objCursor.getString(description);
Promotion promo = new Promotion(resultid, resultrating, resultitle,
resultcompanyid,resultavailbledate,resultdescription, resultsetonfavorite);
promoFavoriteArray.add(promo);
objCursor.moveToNext();//positionnement sur le suivant
}
else
i++;
}
while(objCursor.isLast());
}
}
objCursor.deactivate();
objCursor.close();
return promoFavoriteArray;
}
它只返回给我一个顶行的数组.. 有人知道怎么做?
答案 0 :(得分:1)
如果要检查表中是否有记录。你可以用它。
Cursor cursor=sqLiteDatabase.rawQuery("select * from table limit 1", null);
if (cursor.moveToNext()) {
return true;
}
return false;
它只会返回记录。
答案 1 :(得分:0)
更改行
while(objCursor.isLast());
到
while(!objCursor.isLast());