0
當我在RecyclerView中刪除了一些項目,但它涉及到一個bug時,錯誤很難發生,但它有時會發生。有時該項目不會被刪除,並仍然顯示在recyclerView中,無法永久刪除。以下是我的代碼:recyclerView在循環bug中notifyItemRemoved?
//the positions is a collection,which collect my item positions that should be removed.
int realPosition;
int temp = 0;
for (int i = 0; i < positions.size(); i++) {
realPosition = positions.get(i) - temp;
getAdapter().remove(realPosition);
getAdapter().notifyItemRemoved(realPosition);
temp++;
}
我的英文很差,希望你能理解。誰能幫我?非常感謝你。
THX非常! (int i = positions.size() - 1:i> = 0; i - )' –
如果這有助於您考慮upvoting或將我的答案標記爲答案 – bharath