2011-11-25 75 views
0
private static String[] FROM = { _ID, DESCRIPTION, DATE, TITLE }; 
    //private static String ORDER_BY = _ID + " DESC" ; 
    private Cursor getEvents() { 
    // Perform a managed query. The Activity will handle closing 
    // and re-querying the cursor when needed. 
    SQLiteDatabase db = post.getReadableDatabase(); 
    Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null, 
    null, null); 
    startManagingCursor(cursor); 
    return cursor; 
    }  



private void showEvents(Cursor cursor) { 
      TextView tv = new TextView(this); 
      // Stuff them all into a big string 
      StringBuilder builder = new StringBuilder(
      "Saved events:\n"); 
      while (cursor.moveToNext()) { 
      // Could use getColumnIndexOrThrow() to get indexes 
      long id = cursor.getLong(0); 
      String description = cursor.getString(1); 
      String date = cursor.getString(2); 
      String title = cursor.getString(3); 

     builder.append(id).append(": "); 
      builder.append(description).append(": "); 
      builder.append(date).append(": "); 
      builder.append(title).append("\n"); 

     } 
      // Display on the screen 
      tv.setText(builder); 
      this.setContentView(tv); 

     } 

因此,应该显示数据库的showEvents函数显示比我创建的更大的数据库。它显示了19行,但我只调用了两次insertorthrow函数,所以它应该有两行,所以我不知道它有多于19行。我觉得问题可能在于我的getEvents()函数或showEvents()函数返回光标。帮助将不胜感激。android数据库添加超过需要

+0

数据库将会持续存在,所以您可能会在每次尝试时添加行?尝试卸载并从头开始。 – Ifor

+0

derp,是的,发生了什么事 – Jake

回答

0

使用db shell转到位置并删除数据库。