java - Android : How to iterate on object attributes? -


cursor cursor_daily_data = db.query(table_daily_data, null, null, null, null, null, null);     if (cursor_daily_data.movetofirst()) {         {             dailydata dailydata = new dailydata();             dailydata.time = cursor_daily_data.getstring(0);             dailydata.summary = cursor_daily_data.getstring(1);             dailydata.icon = cursor_daily_data.getstring(2);             dailydata.sunrisetime = cursor_daily_data.getstring(3);             dailydata.sunsettime = cursor_daily_data.getstring(4);             dailydata.moonphase = cursor_daily_data.getstring(5);             dailydata.precipintensity = cursor_daily_data.getstring(6);             dailydata.precipintensitymax = cursor_daily_data.getstring(7);             apiresponse.daily.data.add(dailydata);         } while (cursor_daily_data.movetonext());     }     cursor_daily_data.close();     db.close(); 

is there better way operation? not want use external libraries sugar orm ..etc

without external libraries, no.

anyway, more safer try block:

public list<dailydata> getall() {     list<dailydata> list = new arraylist<>();      sqlitedatabase db = getreadabledatabase();     cursor cursor = db.query(table_daily_data, null, null, null, null, null, null);     try {         if (cursor_daily_data.movetofirst()) {             {                 dailydata dailydata = new dailydata();                 dailydata.time = cursor_daily_data.getstring(0);                 dailydata.summary = cursor_daily_data.getstring(1);                 dailydata.icon = cursor_daily_data.getstring(2);                 dailydata.sunrisetime = cursor_daily_data.getstring(3);                 dailydata.sunsettime = cursor_daily_data.getstring(4);                 dailydata.moonphase = cursor_daily_data.getstring(5);                 dailydata.precipintensity = cursor_daily_data.getstring(6);                 dailydata.precipintensitymax = cursor_daily_data.getstring(7);                 list.add(dailydata);             } while (cursor_daily_data.movetonext());         }     } catch (exception e) {         log.d(tag, "error while trying data database");     } {         if (cursor_daily_data != null && !cursor_daily_data.isclosed()) {             cursor_daily_data.close();         }     }     return list; } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -