For this requirement, there is no need to read and write data frequently. Your mList initialization data is read from the data table at once. You can create a tempList to temporarily store the deleted entry data, and delete the deleted entry data in tempList. Management (add data when there is a deletion operation, remove the corresponding data added during the previous deletion when the action is canceled), and persist the data in the database corresponding to tempList when it is determined that the list no longer needs to be edited (such as when the Activity exits) Operation, when tempList is not empty, tempList is traversed, and the corresponding database table data entry is deleted. At this time, the database transaction operation will be very fast. When tempList is empty, no operation is performed. The entire process is actually performed twice at most. Database operations (mList's query reading and tempList's element mapping table item deletion) save performance expenses. As for the "cancel" Action, to facilitate you to find the corresponding entry data from tempList, it is more appropriate to create tempList with Map ( Such as Map<position, thingsModel>). The database table can delete and modify a single entry. There is no need to delete the table and rebuild it. This is too costly. Deleting data is generally small-scale after all.
Deletion on the UI does not require physical deletion. When restoring, just insert it directly into the original position.
Use a list to store the operations you just performed
// 存在list 中
List<Action> actions = new ArrayList<>();
// 每做一步操作放一个,这样就可以一步一步的回退了。
// 删除不要做物理操作
// 操作的数据结构如下
class Action{
public final static int REMOVE = 0x2;
public final static int INSERT = 0x2;
public final static int UPDATE = 0x2;
private int actionMod;
private int id;
private String table;
}
Refer to the database processing method. User deletion is not a real deletion, but a mark in a field that the data has been deleted. Users cannot see it and think it has been deleted
For this requirement, there is no need to read and write data frequently. Your mList initialization data is read from the data table at once. You can create a tempList to temporarily store the deleted entry data, and delete the deleted entry data in tempList. Management (add data when there is a deletion operation, remove the corresponding data added during the previous deletion when the action is canceled), and persist the data in the database corresponding to tempList when it is determined that the list no longer needs to be edited (such as when the Activity exits) Operation, when tempList is not empty, tempList is traversed, and the corresponding database table data entry is deleted. At this time, the database transaction operation will be very fast. When tempList is empty, no operation is performed. The entire process is actually performed twice at most. Database operations (mList's query reading and tempList's element mapping table item deletion) save performance expenses. As for the "cancel" Action, to facilitate you to find the corresponding entry data from tempList, it is more appropriate to create tempList with Map ( Such as Map<position, thingsModel>). The database table can delete and modify a single entry. There is no need to delete the table and rebuild it. This is too costly. Deleting data is generally small-scale after all.
Deletion on the UI does not require physical deletion. When restoring, just insert it directly into the original position.
Use a list to store the operations you just performed
Refer to the database processing method. User deletion is not a real deletion, but a mark in a field that the data has been deleted. Users cannot see it and think it has been deleted