日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android批量删除图片,Android RecyclerView单点、批量数据元素项目item的增加、删除和移动...

發布時間:2025/3/21 Android 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android批量删除图片,Android RecyclerView单点、批量数据元素项目item的增加、删除和移动... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android RecyclerView單點、批量數據元素項目item的增加、刪除和移動

前文附錄1,2介紹了基本的Android RecyclerView單點、批量元素項目的更新。現在給出其他比較重要的Android RecyclerView數據元素項目的刪除和增加,刪除和增加包含兩種,一種是單點,另外一種是批量的元素。

(一)RecyclerView刪除操作。

(a)單點刪除:notifyItemRemoved(int position)

/**

* Notify any registered observers that the item previously located at position

* has been removed from the data set. The items previously located at and after

* position may now be found at oldPosition - 1.

*

*

This is a structural change event. Representations of other existing items in the

* data set are still considered up to date and will not be rebound, though their positions

* may be altered.

*

* @param position Position of the item that has now been removed

*

* @see #notifyItemRangeRemoved(int, int)

*/

public final void notifyItemRemoved(int position) {

mObservable.notifyItemRangeRemoved(position, 1);

}

在給adapter維持的數據隊列刪除一個元素后,調用此方法,該方法刪除指定位置position的元素并更新RecyclerView。

(b)批量刪除:notifyItemRangeRemoved(int positionStart, int itemCount)

public void notifyItemRangeRemoved(int positionStart, int itemCount) {

// since onItemRangeRemoved() is implemented by the app, it could do anything, including

// removing itself from {@link mObservers} - and that could cause problems if

// an iterator is used on the ArrayList {@link mObservers}.

// to avoid such problems, just march thru the list in the reverse order.

for (int i = mObservers.size() - 1; i >= 0; i--) {

mObservers.get(i).onItemRangeRemoved(positionStart, itemCount);

}

}

在給adapter維持的數據元素隊列批量刪除若干元素后,調用該方法,該方法刪除從開始位置positionStart起之后的itemCount個數量的子元素,然后更新RecyclerView。

(二)RecyclerView增加操作。

(a)單點增加:notifyItemInserted(int position)

/**

* Notify any registered observers that the item reflected at position

* has been newly inserted. The item previously at position is now at

* position position + 1.

*

*

This is a structural change event. Representations of other existing items in the

* data set are still considered up to date and will not be rebound, though their

* positions may be altered.

*

* @param position Position of the newly inserted item in the data set

*

* @see #notifyItemRangeInserted(int, int)

*/

public final void notifyItemInserted(int position) {

mObservable.notifyItemRangeInserted(position, 1);

}在給adapter指定位置position增加一個元素后,調用notifyItemInserted方法,更新RecyclerView。

(b)批量增加:notifyItemRangeInserted(int positionStart, int itemCount)

public void notifyItemRangeInserted(int positionStart, int itemCount) {

// since onItemRangeInserted() is implemented by the app, it could do anything,

// including removing itself from {@link mObservers} - and that could cause problems if

// an iterator is used on the ArrayList {@link mObservers}.

// to avoid such problems, just march thru the list in the reverse order.

for (int i = mObservers.size() - 1; i >= 0; i--) {

mObservers.get(i).onItemRangeInserted(positionStart, itemCount);

}

}在給adapter適配器指定位置positionStart增加itemCount個數據元素后,調用此方法,更新RecyclerView。

(三)RecyclerView移動操作。

notifyItemMoved(int fromPosition, int toPosition)

/**

* Notify any registered observers that the item reflected at fromPosition

* has been moved to toPosition.

*

*

This is a structural change event. Representations of other existing items in the

* data set are still considered up to date and will not be rebound, though their

* positions may be altered.

*

* @param fromPosition Previous position of the item.

* @param toPosition New position of the item.

*/

public final void notifyItemMoved(int fromPosition, int toPosition) {

mObservable.notifyItemMoved(fromPosition, toPosition);

}

移動操作的對象位置有兩個,開始對象位置fromPosition和目的地址位置toPosition。設定這兩個位置后,fromPosition元素位置的元素被移動到toPosition。fromPosition和toPosition是元素的集合隊列中的下標。

附錄:

1,《 Android RecyclerView更新子項目notifyItemChanged》鏈接:http://blog.csdn.net/zhangphil/article/details/78565738

2,《Android RecyclerView批量更新notifyItemRangeChanged》鏈接:http://blog.csdn.net/zhangphil/article/details/78579849

總結

以上是生活随笔為你收集整理的android批量删除图片,Android RecyclerView单点、批量数据元素项目item的增加、删除和移动...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。