当前位置: 首页>>代码示例>>Java>>正文


Java Adapter类代码示例

本文整理汇总了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();
		}
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:21,代码来源:BriarRecyclerView.java

示例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);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:17,代码来源:BriarRecyclerView.java

示例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;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:29,代码来源:PullToRefreshRecyclerView.java

示例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;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:31,代码来源:PullToRefreshRecyclerView.java

示例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();
        }
    }
}
 
开发者ID:lucastanziano,项目名称:Blockbuster,代码行数:28,代码来源:ItemSelectionSupport.java

示例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;
}
 
开发者ID:mobvoi,项目名称:ticdesign,代码行数:18,代码来源:FocusableLinearLayoutManager.java

示例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);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:20,代码来源:PlayRecyclerView.java

示例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;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:28,代码来源:SelectableListLayout.java

示例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();
        }
    }
}
 
开发者ID:cymcsg,项目名称:UltimateAndroid,代码行数:28,代码来源:ItemSelectionSupport.java

示例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);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:16,代码来源:BriarRecyclerView.java

示例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()));
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:15,代码来源:SelectableListLayout.java

示例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;
        }
    });
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:RcvAdapterWrapper.java

示例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();
    }
}
 
开发者ID:lucastanziano,项目名称:Blockbuster,代码行数:10,代码来源:TwoWayLayoutManager.java

示例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()));
        }
    }
 
开发者ID:joy-inc,项目名称:joy-library,代码行数:15,代码来源:RecyclerAdapter.java

示例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());
    }
 
开发者ID:joy-inc,项目名称:joy-library,代码行数:16,代码来源:RecyclerAdapter.java


注:本文中的android.support.v7.widget.RecyclerView.Adapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。