鴻蒙OS BaseItemProvider

2022-09-13 11:22 更新

BaseItemProvider

java.lang.Object

|---ohos.agp.components.BaseItemProvider

public abstract class BaseItemProvider
extends Object

提供 BaseItemProvider 對象以將 ComponentProvider 項與組件的基本數(shù)據(jù)相關聯(lián)。

提供者提供對數(shù)據(jù)項的訪問并為數(shù)據(jù)集中的每個項創(chuàng)建一個組件。 當數(shù)據(jù)集中的內(nèi)容發(fā)生變化時,通知訂閱者響應變化,并在屏幕上同步刷新更新的內(nèi)容。

構造函數(shù)摘要

構造函數(shù) 描述
BaseItemProvider() 構造函數(shù)

方法總結

修飾符和類型 方法 描述
void addDataSubscriber(DataSetSubscriber subscriber) 添加數(shù)據(jù)集訂閱者。
abstract Component getComponent(int position, Component convertComponent, ComponentContainer parent) 獲取在數(shù)據(jù)集中指定位置顯示數(shù)據(jù)的組件。
int getComponentTypeCount() 獲取數(shù)據(jù)集中所有項目的組件類型數(shù)。
abstract int getCount() 獲取提供程序中的數(shù)據(jù)項總數(shù)。
TextFilter getFilter() 獲取文本過濾器。
abstract Object getItem(int position) 獲取數(shù)據(jù)集中指定位置的數(shù)據(jù)項。
int getItemComponentType(int position) 根據(jù)位置獲取數(shù)據(jù)集中數(shù)據(jù)項的組件類型。
abstract long getItemId(int position) 獲取數(shù)據(jù)集中指定位置的數(shù)據(jù)項的行ID。
void notifyDataChanged() 刷新已更新數(shù)據(jù)項的組件。
void notifyDataInvalidated() 當提供者數(shù)據(jù)無效時調(diào)用。
void notifyDataSetItemChanged(int position) 刷新已更新數(shù)據(jù)項的組件。
void notifyDataSetItemInserted(int position) 刷新指定數(shù)據(jù)項已更改的組件。
void notifyDataSetItemRangeChanged(int startPos, int countItems) 刷新從給定位置開始的指定數(shù)量的數(shù)據(jù)項已更改的組件。
void notifyDataSetItemRangeInserted(int startPos, int countItems) 刷新從給定位置開始插入了指定數(shù)量的數(shù)據(jù)項的組件。
void notifyDataSetItemRangeRemoved(int startPos, int countItems) 刷新已刪除從給定位置開始的指定數(shù)量數(shù)據(jù)項的組件。
void notifyDataSetItemRemoved(int position) 刷新已從中刪除指定數(shù)據(jù)項的組件。
void onItemMoved(int from, int to) 當組件項應移動到數(shù)據(jù)集中的其他位置時在內(nèi)部調(diào)用。
void removeDataSubscriber(DataSetSubscriber subscriber) 刪除數(shù)據(jù)集訂閱者。
void setFilter(TextFilter filter) 設置文本過濾器。
從類 java.lang.Object 繼承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

構造函數(shù)相信信息

BaseItemProvider

public BaseItemProvider()

構造函數(shù)

方法詳情

getCount

public abstract int getCount()

獲取提供程序中的數(shù)據(jù)項總數(shù)。

返回:

返回提供程序中的數(shù)據(jù)項總數(shù)。

getItem

public abstract Object getItem(int position)

獲取數(shù)據(jù)集中指定位置的數(shù)據(jù)項。

參數(shù):

參數(shù)名稱 參數(shù)描述
position 表示數(shù)據(jù)項在數(shù)據(jù)集中的位置。

返回:

返回指定位置的數(shù)據(jù)項。

getItemId

public abstract long getItemId(int position)

獲取數(shù)據(jù)集中指定位置的數(shù)據(jù)項的行ID。

參數(shù):

參數(shù)名稱 參數(shù)描述
position 表示數(shù)據(jù)項的行ID的位置。

返回:

返回指定位置的數(shù)據(jù)項的行 ID。

getComponent

public abstract Component getComponent(int position, Component convertComponent, ComponentContainer parent)

獲取在數(shù)據(jù)集中指定位置顯示數(shù)據(jù)的組件。

參數(shù):

參數(shù)名稱 參數(shù)描述
position 表示組件在數(shù)據(jù)集中的位置。
convertComponent 表示要重用的前一個組件。 如果沒有此類組件,則此參數(shù)可以為 null。
parent 表示與要獲取的組件匹配的父組件。

返回:

返回與指定位置的數(shù)據(jù)項匹配的組件。

getItemComponentType

public int getItemComponentType(int position)

根據(jù)位置獲取數(shù)據(jù)集中數(shù)據(jù)項的組件類型。

每次將組件布局添加到數(shù)據(jù)集時,都必須添加組件類型以匹配組件布局。 組件類型取值范圍從 0 到 getComponentTypeCount() 的結果減 1。例如,包含一個鍵的組件布局匹配組件類型值 0,包含兩個鍵的組件布局匹配組件類型值 1。

參數(shù):

參數(shù)名稱 參數(shù)描述
position 指示組件項在提供程序數(shù)據(jù)集中的位置。

返回:

返回組件類型。

getComponentTypeCount

public int getComponentTypeCount()

獲取數(shù)據(jù)集中所有項目的組件類型數(shù)。 默認情況下,組件類型的數(shù)量為 1。

返回:

返回數(shù)據(jù)集中所有項目的組件類型數(shù)。

notifyDataChanged

public void notifyDataChanged()

刷新已更新數(shù)據(jù)項的組件。

使用 DataSetPublisher#notifyChanged() 方法通知每個注冊的訂閱者。

notifyDataInvalidated

public void notifyDataInvalidated()

當提供者數(shù)據(jù)無效時調(diào)用。

使用 DataSetPublisher#informInvalidated() 方法通知每個注冊的訂閱者。

notifyDataSetItemChanged

public void notifyDataSetItemChanged(int position)

刷新已更新數(shù)據(jù)項的組件。

使用 DataSetPublisher#notifyItemChanged(int) 方法通知每個注冊的訂閱者。

參數(shù):

參數(shù)名稱 參數(shù)描述
position 表示項目在數(shù)據(jù)集中的位置。

notifyDataSetItemInserted

public void notifyDataSetItemInserted(int position)

刷新指定數(shù)據(jù)項已更改的組件。

要通知數(shù)據(jù)更改訂閱者,請調(diào)用 DataSetPublisher#notifyItemChanged(int)。

參數(shù):

參數(shù)名稱 參數(shù)描述
position 指示更改的數(shù)據(jù)項在數(shù)據(jù)集中的位置。

notifyDataSetItemRemoved

public void notifyDataSetItemRemoved(int position)

刷新已從中刪除指定數(shù)據(jù)項的組件。

要通知數(shù)據(jù)更改訂閱者,請調(diào)用 DataSetPublisher#notifyItemRemoved(int)。

參數(shù):

參數(shù)名稱 參數(shù)描述
position 表示被移除的數(shù)據(jù)項在數(shù)據(jù)集中的位置。

notifyDataSetItemRangeChanged

public void notifyDataSetItemRangeChanged(int startPos, int countItems)

刷新從給定位置開始的指定數(shù)量的數(shù)據(jù)項已更改的組件。

要通知數(shù)據(jù)更改訂閱者,請調(diào)用 DataSetPublisher#notifyItemRangeChanged(int, int)。

參數(shù):

參數(shù)名稱 參數(shù)描述
startPos 指示已更改的第一個數(shù)據(jù)項的位置。
countItems 指示已更改的數(shù)據(jù)項數(shù)。

notifyDataSetItemRangeInserted

public void notifyDataSetItemRangeInserted(int startPos, int countItems)

刷新從給定位置開始插入了指定數(shù)量的數(shù)據(jù)項的組件。

要通知數(shù)據(jù)更改訂閱者,請調(diào)用 DataSetPublisher#notifyItemRangeInserted(int, int)。

參數(shù):

參數(shù)名稱 參數(shù)描述
startPos 指示已插入的第一個數(shù)據(jù)項的位置。
countItems 表示已插入的數(shù)據(jù)項數(shù)。

notifyDataSetItemRangeRemoved

public void notifyDataSetItemRangeRemoved(int startPos, int countItems)

刷新已刪除從給定位置開始的指定數(shù)量數(shù)據(jù)項的組件。

要通知數(shù)據(jù)更改訂閱者,請調(diào)用 DataSetPublisher#notifyItemRangeRemoved(int, int)。

參數(shù):

參數(shù)名稱 參數(shù)描述
startPos 指示已刪除的第一個數(shù)據(jù)項的位置。
countItems 表示已刪除的數(shù)據(jù)項數(shù)。

addDataSubscriber

public final void addDataSubscriber(DataSetSubscriber subscriber)

添加數(shù)據(jù)集訂閱者。

參數(shù):

參數(shù)名稱 參數(shù)描述
subscriber 指示訂閱者在數(shù)據(jù)集中的內(nèi)容發(fā)生更改時通知。

removeDataSubscriber

public final void removeDataSubscriber(DataSetSubscriber subscriber)

刪除數(shù)據(jù)集訂閱者。

參數(shù):

參數(shù)名稱 參數(shù)描述
subscriber 指示訂閱者在數(shù)據(jù)集中的內(nèi)容發(fā)生更改時通知。

setFilter

public void setFilter(TextFilter filter)

設置文本過濾器。

參數(shù):

參數(shù)名稱 參數(shù)描述
filter 表示文本過濾器。

getFilter

public TextFilter getFilter()

獲取文本過濾器。

返回:

返回文本過濾器。

onItemMoved

public void onItemMoved(int from, int to)

當組件項應移動到數(shù)據(jù)集中的其他位置時在內(nèi)部調(diào)用。

參數(shù):

參數(shù)名稱 參數(shù)描述
from 表示組件項在數(shù)據(jù)集中的原始位置。
to 表示組件項在數(shù)據(jù)集中的目標位置。
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號