android - recyclerview如何在onswipe删除数据后如何恢复数据。
大家讲道理
大家讲道理 2017-04-17 16:37:59
0
3
444
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
小葫芦

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.

Peter_Zhu

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;
}
Peter_Zhu

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!