app/src/main/java/com/example/steve/todoandroid/ToDoListActivity.java
// Since we're trying to ID the DB records using listview positions, every time you delete something in the middle of the list we need to shift everything.
Since we're trying to ID the DB records using listview positions, every time you delete something in the middle of the list we need to shift everything.
Since we ' re trying to ID the DB records using listview positions every time you delete something in the middle of the list we need to shift everything .
private void updateDBPositions()
    {
        ArrayList<String> prevPos;
        prevPos = toDoListDB.getAllListPos();
        for(int i=0 ; i<prevPos.size() ; i++)
        {
            if (i !=  Integer.parseInt(prevPos.get(i)))
            {
                toDoListDB.updateListPos(Integer.parseInt(prevPos.get(i)),i);
            }
        }
    }
private void updateDBPositions ( ) { ArrayList < String > prevPos ; prevPos = toDoListDB . getAllListPos ( ) ; for ( int i = 0 ; i < prevPos . size ( ) ; i ++ ) { if ( i != Integer . parseInt ( prevPos . get ( i ) ) ) { toDoListDB . updateListPos ( Integer . parseInt ( prevPos . get ( i ) ) , i ) ; } } }
Since we're trying to ID the DB records using listview positions, every time you delete something in the middle of the list we need to shift everything.
Since we ' re trying to ID the DB records using listview positions every time you delete something in the middle of the list we need to shift everything .
//update all positions that have changed.  Since the list view always uses a sequential position, the DB needs to keep track of what position the record is currently in. //Note: This should be done using a key-value pair.  The ID is the primary key on the DB, whereas the pos is not so this is a hackish solution. // While POS is unique due to the nature of listview, it's better to properly identify the key-value pair using a PK+position.