I would like all new items to be added at the top, ie, if ROW-ID 1,2,3 are taken and I add a new item, it should be added at position 1, and rest should be shifted. But right now when I add an item, it gets added at ID 4 (ie at the back).
Method
Temp_Cover_StoryBaseList_DatabaseHandler db = new Temp_Cover_StoryBaseList_DatabaseHandler(context, currentUsername);
db.addStory(pointer, filePath);
db.close();
_
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db)
{
String CREATE_STORIES_TABLE
= "CREATE TABLE " + TABLE_TEMP_BASESTORY_LIST
+ "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_POINTER + " STRING,"
+ KEY_URI + " STRING"
+ ")";
db.execSQL(CREATE_STORIES_TABLE);
}
_
// Adding new Story
public void addStory(String pointer, String filePath)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_POINTER, pointer );
values.put(KEY_URI, filePath );
// Inserting Row
long id = db.insert(TABLE_TEMP_BASESTORY_LIST, null, values);
Log.d(TAG, "TempCover ID:" + Long.toString(id));
db.close();
}
_
public List<StoryData> getAllStories()
{
List<StoryData> storyDataList = new ArrayList<StoryData>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_STORIES_LIST;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if(cursor !=null)
{
if (cursor.moveToFirst())
{
do
{
ArrayList<Integer> coverList = new ArrayList<Integer>();
coverList.add( cursor.getInt(4) );
coverList.add( cursor.getInt(5) );
StoryData sData = new StoryData
(
cursor.getInt(0),
cursor.getString(1),
cursor.getString(2),
cursor.getInt(3),
coverList,
Long.parseLong(cursor.getString(6)),
Boolean.parseBoolean(cursor.getString(7)),
cursor.getString(8)
);
// Adding contact to list
storyDataList.add(sData);
} while (cursor.moveToNext());
}
}
return storyDataList;
}