我沒有在RecyclerView上定製任何內容,所以添加/刪除了項目上的默認動畫。雖然我發現動畫不能按我的預期工作。當我用下面的代碼刪除項目:從RecyclerView中刪除項目效果不佳
mComments.remove(position);
notifyItemRemoved(position);
我在UI上看到它總是刪除錯誤的,而應該被刪除已經不斷顯示出來,並覆蓋其他人。
new CountDownTimer(60000, 1000) {
@Override
public void onTick(long l) {
for (int i = 0; i < mComments.size(); i++) {
RoomMessage item = mComments.get(i);
item.timeRemaining -= 1000;
if (item.timeRemaining <= 0) {
Log.v(TAG, "Going to remove no." + i + ". And the content = " + mComments.get(i).text);
removeAt(i);
}
}
}
@Override
public void onFinish() {
start();
}
}.start();
根據日誌,我沒有刪除正確的。如下所示。
02-16 15:26:38.274 21861-21861/com.xxxx.android V/ChatsAdapter: Going to remove no.0. And the content = 1
02-16 15:26:41.284 21861-21861/com.xxxx.android V/ChatsAdapter: Going to remove no.0. And the content = 2
02-16 15:26:42.284 21861-21861/com.xxxx.android V/ChatsAdapter: Going to remove no.0. And the content = 3
我做錯了什麼?
順便說一句我已經設置setisRecyclable(false)
@Dayo Choul有沒有更新? –
已更新。這很奇怪,根據日誌我刪除了正確的一個,而在屏幕上它總是刪除錯誤的... –
@Dayo Choul所以我的回答沒有幫助你嗎?你也可以發佈日誌。我回答動畫。 –