I find myself using this bit of code very often when I am retrieving the results from a Cursor
SearchItem searchItem = new SearchItem();
searchItem.setId(cursor.getInt(cursor.getColumnIndex(COLUMN_NAME_ID)));
searchItem.setOrigin(cursor.getString(cursor.getColumnIndex(COLUMN_NAME_ORIGIN)));
searchItem.setDestination(cursor.getString(cursor.getColumnIndex(COLUMN_NAME_DESTINATION)));
searchItem.setTimeStamp(cursor.getLong(cursor.getColumnIndex(COLUMN_NAME_TIMESTAMP)));
Specifically this could be when I am using a CursorAdapter
for a ListView
and in a DAO object.
What would be a useful design pattern to use in this case?
My first instinct is to have a singleton class which does this. Are there any problems in taking this route?