@@ -53,6 +53,8 @@ public void initialize() {
5353 //Read a record from DB
5454 Category category = new Category (cursor .getInt (idColIndex ),
5555 cursor .getString (nameColIndex ));
56+ Log .d (Constants .TAG , "id = " + cursor .getInt (idColIndex ) +
57+ " name = " + cursor .getString (nameColIndex ));
5658
5759 //Add record to list
5860 categories .add (category );
@@ -82,6 +84,12 @@ public void initialize() {
8284 cursor .getString (titleColIndex ),
8385 cursor .getInt (categoryColIndex ),
8486 cursor .getInt (priceColIndex ));
87+ Log .d (Constants .TAG , "id = " + cursor .getInt (idColIndex ) +
88+ " time = " + cursor .getLong (timeColIndex ) +
89+ " type = " + cursor .getInt (typeColIndex ) +
90+ " title = " + cursor .getString (titleColIndex ) +
91+ " category = " + cursor .getInt (categoryColIndex ) +
92+ " price = " + cursor .getInt (priceColIndex ));
8593
8694 //Add record to list
8795 records .add (record );
@@ -96,6 +104,12 @@ public List<Record> getRecords() {
96104 }
97105
98106 public void addRecord (long time , int type , String title , String category , int price ) {
107+ //Add category if it does not exist yet
108+ if (getCategoryIdByName (category ) == -1 ) {
109+ addCategory (category );
110+ }
111+ int category_id = getCategoryIdByName (category );
112+
99113 //Add record to DB
100114 SQLiteDatabase db = dbHelper .getWritableDatabase ();
101115
@@ -110,11 +124,6 @@ public void addRecord(long time, int type, String title, String category, int pr
110124
111125 db .close ();
112126
113- if (getCategoryIdByName (category ) == -1 ) {
114- addCategory (category );
115- }
116- int category_id = getCategoryIdByName (category );
117-
118127 //Add record to app list
119128 records .add (new Record (id , time , type , title , category_id , price ));
120129
@@ -183,6 +192,7 @@ public String getCategoryById(int id) {
183192
184193 public int getCategoryIdByName (String name ) {
185194 for (Category category : categories ) {
195+ Log .d (Constants .TAG , name + " " + category .getName () + " " + category .getName ().equals (name ));
186196 if (category .getName ().equals (name )) {
187197 return category .getId ();
188198 }
0 commit comments