本文整理汇总了Java中android.support.v7.widget.RecyclerView.Adapter.getItemCount方法的典型用法代码示例。如果您正苦于以下问题:Java Adapter.getItemCount方法的具体用法?Java Adapter.getItemCount怎么用?Java Adapter.getItemCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.RecyclerView.Adapter
的用法示例。
在下文中一共展示了Adapter.getItemCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAdapter
import android.support.v7.widget.RecyclerView.Adapter; //导入方法依赖的package包/类
public void setAdapter(Adapter adapter) {
if (recyclerView == null) initViews();
Adapter oldAdapter = recyclerView.getAdapter();
if (oldAdapter != null) {
oldAdapter.unregisterAdapterDataObserver(emptyObserver);
}
recyclerView.setAdapter(adapter);
if (adapter != null) {
adapter.registerAdapterDataObserver(emptyObserver);
if (adapter.getItemCount() > 0) {
// only show data if adapter has data already
// otherwise progress bar is shown
emptyObserver.onChanged();
}
}
}
示例2: isFirstItemVisible
import android.support.v7.widget.RecyclerView.Adapter; //导入方法依赖的package包/类
/**
* @Description: 判断第一个条目是否完全可见
*
* @return boolean:
* @version 1.0
* @date 2015-9-23
* @Author zhou.wenkai
*/
private boolean isFirstItemVisible() {
final Adapter<?> adapter = getRefreshableView().getAdapter();
// 如果未设置Adapter或者Adapter没有数据可以下拉刷新
if (null == adapter || adapter.getItemCount() == 0) {
if (DEBUG) {
Log.d(LOG_TAG, "isFirstItemVisible. Empty View.");
}
return true;
} else {
// 第一个条目完全展示,可以刷新
if (getFirstVisiblePosition() == 0) {
return mRefreshableView.getChildAt(0).getTop() >= mRefreshableView
.getTop();
}
}
return false;
}
示例3: isLastItemVisible
import android.support.v7.widget.RecyclerView.Adapter; //导入方法依赖的package包/类
/**
* @Description: 判断最后一个条目是否完全可见
*
* @return boolean:
* @version 1.0
* @date 2015-9-23
* @Author zhou.wenkai
*/
private boolean isLastItemVisible() {
final Adapter<?> adapter = getRefreshableView().getAdapter();
// 如果未设置Adapter或者Adapter没有数据可以上拉刷新
if (null == adapter || adapter.getItemCount() == 0) {
if (DEBUG) {
Log.d(LOG_TAG, "isLastItemVisible. Empty View.");
}
return true;
} else {
// 最后一个条目View完全展示,可以刷新
int lastVisiblePosition = getLastVisiblePosition();
if(lastVisiblePosition >= mRefreshableView.getAdapter().getItemCount()-1) {
return mRefreshableView.getChildAt(
mRefreshableView.getChildCount() - 1).getBottom() <= mRefreshableView
.getBottom();
}
}
return false;
}
示例4: showData
import android.support.v7.widget.RecyclerView.Adapter; //导入方法依赖的package包/类
public void showData() {
if (recyclerView == null) initViews();
Adapter adapter = recyclerView.getAdapter();
if (adapter != null) {
if (adapter.getItemCount() == 0) {
emptyView.setVisibility(VISIBLE);
recyclerView.setVisibility(INVISIBLE);
} else {
// use GONE here so empty view doesn't use space on small lists
emptyView.setVisibility(GONE);
recyclerView.setVisibility(VISIBLE);
}
progressBar.setVisibility(GONE);
}
}
示例5: onAdapterDataChanged
import android.support.v7.widget.RecyclerView.Adapter; //导入方法依赖的package包/类
public void onAdapterDataChanged() {
final Adapter adapter = mRecyclerView.getAdapter();
if (mChoiceMode == ChoiceMode.NONE || adapter == null || !adapter.hasStableIds()) {
return;
}
final int itemCount = adapter.getItemCount();
// Clear out the positional check states, we'll rebuild it below from IDs.
mCheckedStates.clear();
for (int checkedIndex = 0; checkedIndex < mCheckedIdStates.size(); checkedIndex++) {
final long currentId = mCheckedIdStates.keyAt(checkedIndex);
final int currentPosition = mCheckedIdStates.valueAt(checkedIndex);
final long newPositionId = adapter.getItemId(currentPosition);
if (currentId != newPositionId) {
// Look around to see if the ID is nearby. If not, uncheck it.
final int start = Math.max(0, currentPosition - CHECK_POSITION_SEARCH_DISTANCE);
final int end = Math.min(currentPosition + CHECK_POSITION_SEARCH_DISTANCE, itemCount);
boolean found = false;
for (int searchPos = start; searchPos < end; searchPos++) {
final long searchId = adapter.getItemId(searchPos);
if (currentId == searchId) {
found = true;
mCheckedStates.put(searchPos, true);
mCheckedIdStates.setValueAt(checkedIndex, searchPos);
break;
}
}
if (!found) {
mCheckedIdStates.delete(currentId);
mCheckedCount--;
checkedIndex--;
}
} else {
mCheckedStates.put(currentPosition, true);
}
}
}
示例6: isFooter
import android.support.v7.widget.RecyclerView.Adapter; //导入方法依赖的package包/类
public boolean isFooter(int position) {
Adapter adapter = mList.getAdapter();
return adapter != null && position >= adapter.getItemCount() - mFooters;
}