2013-07-28 34 views
0

我正在解析數據數據庫中的數據。我面臨的問題是每當應用程序通過調用dataList()開始獲取數據時。現在,我想使用一個條件來檢查是否錯誤是empty只有fecth數據從數據庫或我不想在數據庫中有任何重複的數據。我嘗試下面的代碼,但沒有成功檢查遊標有任何數據

boolean isEmpty = cursor.getCount() < 1; 
     if(!isEmpty){ 
      cursor = db.rawQuery("my query..", null); 
     }else{ 
      dataList(); 
      cursor = db.rawQuery("my query..", null); 
     } 
+0

無需在標題標籤。標籤系統負責這一點。請閱讀http://meta.stackexchange.com/q/19190/147072瞭解更多信息。 – Patrick

回答

1

嘗試

boolean isEmpty; 
if(cursor!=null && cursor.getCount()>0) 
{ 
isEmpty=false; 
} 
else 
{ 
isEmpty=true; 
} 

if(isEmpty){ 
      cursor = db.rawQuery("my query..", null); 
     }else{ 
      dataList(); 
      cursor = db.rawQuery("my query..", null); 
     } 
0
 if (!(mCursor.moveToFirst()) || mCursor.getCount() ==0){ 
     { 
      dataList(); 
     cursor = db.rawQuery("my query..", null); 
     }else{ 
      cursor = db.rawQuery("my query..", null); 
     }