本文整理汇总了Java中android.support.v7.widget.RecyclerView.Adapter类的典型用法代码示例。如果您正苦于以下问题:Java Adapter类的具体用法?Java Adapter怎么用?Java Adapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Adapter类属于android.support.v7.widget.RecyclerView包,在下文中一共展示了Adapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: startPeriodicUpdate
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
public void startPeriodicUpdate() {
if (recyclerView == null || recyclerView.getAdapter() == null) {
throw new IllegalStateException("Need to call setAdapter() first!");
}
refresher = new Runnable() {
@Override
public void run() {
LOG.info("Updating Content...");
Adapter adapter = recyclerView.getAdapter();
adapter.notifyItemRangeChanged(0, adapter.getItemCount());
handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
}
};
LOG.info("Adding Handler Callback");
handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
}
示例3: 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;
}
示例4: 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;
}
示例5: setChoiceMode
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
/**
* Defines the choice behavior for the List. By default, Lists do not have any choice behavior
* ({@link ChoiceMode#NONE}). By setting the choiceMode to {@link ChoiceMode#SINGLE}, the
* List allows up to one item to be in a chosen state. By setting the choiceMode to
* {@link ChoiceMode#MULTIPLE}, the list allows any number of items to be chosen.
*
* @param choiceMode One of {@link ChoiceMode#NONE}, {@link ChoiceMode#SINGLE}, or
* {@link ChoiceMode#MULTIPLE}
*/
public void setChoiceMode(ChoiceMode choiceMode) {
if (mChoiceMode == choiceMode) {
return;
}
mChoiceMode = choiceMode;
if (mChoiceMode != ChoiceMode.NONE) {
if (mCheckedStates == null) {
mCheckedStates = new CheckedStates();
}
final Adapter adapter = mRecyclerView.getAdapter();
if (mCheckedIdStates == null && adapter != null && adapter.hasStableIds()) {
mCheckedIdStates = new CheckedIdStates();
}
}
}
示例6: validAdapter
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
@Override
public boolean validAdapter(Adapter adapter) {
if (adapter != null) {
RecyclerView.ViewHolder viewHolder = adapter.createViewHolder(mTicklableRecyclerView,
adapter.getItemViewType(0));
if (!(viewHolder instanceof ViewHolder)) {
String msg = "adapter's ViewHolder should be instance of FocusableLinearLayoutManager.ViewHolder";
if (DesignConfig.DEBUG) {
throw new IllegalArgumentException(msg);
} else {
Log.w(TAG, msg);
return false;
}
}
}
return true;
}
示例7: setupEmptyViewObserver
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
private void setupEmptyViewObserver(RecyclerView.Adapter paramAdapter)
{
if (paramAdapter != null)
{
if (this.mObserver != null)
{
paramAdapter.unregisterAdapterDataObserver(this.mObserver);
this.mObserver = null;
}
this.mObserver = new RecyclerView.AdapterDataObserver()
{
public final void onChanged()
{
PlayRecyclerView.this.updateEmptyStatus();
}
};
paramAdapter.registerAdapterDataObserver(this.mObserver);
}
}
示例8: initializeRecyclerView
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
/**
* Initializes the RecyclerView.
*
* @param adapter The adapter that provides a binding from an app-specific data set to views
* that are displayed within the RecyclerView.
* @return The RecyclerView itself.
*/
public RecyclerView initializeRecyclerView(Adapter<RecyclerView.ViewHolder> adapter) {
mAdapter = adapter;
mAdapter.registerAdapterDataObserver(mAdapterObserver);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
setToolbarShadowVisibility();
}
});
mItemAnimator = mRecyclerView.getItemAnimator();
return mRecyclerView;
}
示例9: setChoiceMode
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
/**
* Defines the choice behavior for the List. By default, Lists do not have any choice behavior
* ({@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#NONE}). By setting the choiceMode to {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#SINGLE}, the
* List allows up to one item to be in a chosen state. By setting the choiceMode to
* {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#MULTIPLE}, the list allows any number of items to be chosen.
*
* @param choiceMode One of {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#NONE}, {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#SINGLE}, or
* {@link com.marshalchen.common.uimodule.twowayview.ItemSelectionSupport.ChoiceMode#MULTIPLE}
*/
public void setChoiceMode(ChoiceMode choiceMode) {
if (mChoiceMode == choiceMode) {
return;
}
mChoiceMode = choiceMode;
if (mChoiceMode != ChoiceMode.NONE) {
if (mCheckedStates == null) {
mCheckedStates = new CheckedStates();
}
final Adapter adapter = mRecyclerView.getAdapter();
if (mCheckedIdStates == null && adapter != null && adapter.hasStableIds()) {
mCheckedIdStates = new CheckedIdStates();
}
}
}
示例10: 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);
}
}
示例11: initializeRecyclerView
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
/**
* Initializes the RecyclerView.
*
* @param adapter The adapter that provides a binding from an app-specific data set to views
* that are displayed within the RecyclerView.
*/
public void initializeRecyclerView(Adapter<RecyclerView.ViewHolder> adapter) {
mAdapter = adapter;
mAdapter.registerAdapterDataObserver(mAdapterObserver);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
示例12: setSpanSizeLookup
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
static void setSpanSizeLookup(final Adapter adapter, final GridLayoutManager layoutManager) {
layoutManager.setSpanSizeLookup(new SpanSizeLookup() {
public int getSpanSize(int position) {
int type = adapter.getItemViewType(position);
if (type == RcvAdapterWrapper.TYPE_HEADER || type == RcvAdapterWrapper.TYPE_FOOTER) {
return layoutManager.getSpanCount();
}
return 1;
}
});
}
示例13: onAdapterChanged
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
@Override
public void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter) {
super.onAdapterChanged(oldAdapter, newAdapter);
final ItemSelectionSupport itemSelectionSupport = ItemSelectionSupport.from(mRecyclerView);
if (oldAdapter != null && itemSelectionSupport != null) {
itemSelectionSupport.clearChoices();
}
}
示例14: RecyclerAdapter
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
public RecyclerAdapter(Adapter<ViewHolder> adapter, LayoutManager lm) {
mHeaderArrays = new SparseArray<>();
mFooterArrays = new SparseArray<>();
setWrappedAdapter(adapter);
mLayoutManager = lm;
if (lm instanceof GridLayoutManager) {
GridLayoutManager glm = (GridLayoutManager) lm;
glm.setSpanSizeLookup(new SpanSizeLookup(this, glm.getSpanCount()));
}
}
示例15: setWrappedAdapter
import android.support.v7.widget.RecyclerView.Adapter; //导入依赖的package包/类
private void setWrappedAdapter(Adapter<ViewHolder> adapter) {
if (adapter == null)
return;
if (mAdapter != null) {
notifyItemRangeRemoved(getHeadersCount(), getWrappedItemCount());
mAdapter.unregisterAdapterDataObserver(mDataObserver);
}
mAdapter = adapter;
mAdapter.registerAdapterDataObserver(mDataObserver);
notifyItemRangeInserted(getHeadersCount(), getWrappedItemCount());
}