Invalid number id is initialized twice

I have a horizontal view of the recycler with custom elements in it. Each element can hold the position of the current element in the Recycler view. I want to update the position of a position when an element is moved using drag and drop. However, data is deleted when there are more than three items in the horizontal view. Please help me. Source

This is what I get in Logcat:

E / ROOM: The invalidation alarm is initialized twice: /.

E / Moved: Counterfrom3

next item: to2

Initializing a database in onCreate.

 db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, DB_NAME)
                .fallbackToDestructiveMigration()
                .allowMainThreadQueries()
                .build();

RecyclerView adapter code.

@Override
public boolean onItemMove(int fromPosition, int toPosition) {
    String name = dataSet.get(fromPosition).getName();
    //this will make "Add item" do not move from its first position..
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (!(Objects.equals(name, "Add") || (toPosition == 0 && fromPosition == 1))) {
            Collections.swap(dataSet, fromPosition, toPosition);
            MoveItem(fromPosition, toPosition);
            notifyItemMoved(fromPosition, toPosition);
            return true;
        }
    }
    return false;
}

Code to update data when moving items.

 public static void MoveItem(int fromPosition,int toPosition){
        String name = data.get(fromPosition).getName(); //This gets the current item name in the view 
        String nexName = data.get(toPosition).getName(); //This gets the next item name in the view 

        ContentValues fromContentValues = new ContentValues();
        fromContentValues.put("posItem", toPosition); //adding data to ContentValues
        ContentValues toContentValues = new ContentValues();
        toContentValues.put("posItem", fromPosition);
        Log.e("Item moved", name + "from" + fromPosition + "\n" + "next item:" + "to" + toPosition);

        db.beginTransaction();
        try {
        db.getOpenHelper().getWritableDatabase().update(name,
                0, fromContentValues, "posItem =" + fromPosition, null);

        db.getOpenHelper().getWritableDatabase().update(nexName,
                0, toContentValues, "posItem =" + toPosition, null);
        db.setTransactionSuccessful(); //setting Transaction Successful
        } finally {
            db.endTransaction(); // commit or rollback
            db.close(); //closing database
        }
    }
+4
source share

Source: https://habr.com/ru/post/1690370/


All Articles