本文整理匯總了Java中android.support.v7.widget.RecyclerView.getAdapter方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.getAdapter方法的具體用法?Java RecyclerView.getAdapter怎麽用?Java RecyclerView.getAdapter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.getAdapter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* @since 5.0.0-b4
*/
@SuppressWarnings({"ConstantConditions", "unchecked", "SuspiciousNameCombination"})
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) {
int offset = (mDivider != null && withOffset ? mDivider.getIntrinsicHeight() : 0);
if (mSectionOffset > 0 && recyclerView.getAdapter() instanceof FlexibleAdapter) {
FlexibleAdapter flexibleAdapter = (FlexibleAdapter) recyclerView.getAdapter();
int position = recyclerView.getChildAdapterPosition(view);
//Only ISectionable items can finish with a gap and only if next item is a IHeader item
if (flexibleAdapter.getItem(position) instanceof ISectionable &&
(flexibleAdapter.isHeader(flexibleAdapter.getItem(position + 1)) ||
position >= recyclerView.getAdapter().getItemCount() - 1)) {
offset += mSectionOffset;
}
}
if (Utils.getOrientation(recyclerView.getLayoutManager()) == RecyclerView.VERTICAL) {
outRect.set(0, 0, 0, offset);
} else {
outRect.set(0, 0, offset, 0);
}
}
示例2: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
RecyclerView.Adapter<?> adapter = parent.getAdapter();
if (adapter == null) {
return;
}
int count = adapter.getItemCount();
int position = parent.getChildAdapterPosition(view);
if (mOrientation == LinearLayoutManager.VERTICAL) {
vertical(outRect, count, position);
} else {
horizontal(outRect, count, position);
}
}
示例3: onScrolled
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
// init
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (layoutManager.getChildCount() > 0) {
// Calculate
int indexOfLastItemViewVisible = layoutManager.getChildCount() -1;
View lastItemViewVisible = layoutManager.getChildAt(indexOfLastItemViewVisible);
int adapterPosition = layoutManager.getPosition(lastItemViewVisible);
boolean isLastItemVisible = (adapterPosition == adapter.getItemCount() -1);
/**
* Here you should load more items because user is seeing the last item of the list.
* Advice: you should add a boolean value to the class
* so that the method {@link #loadPage()} will be triggered only once
* and not every time the user touch the screen ;)
**/
if (isLastItemVisible)
loadPage();
}
}
示例4: onScrollStateChanged
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
moreAdapter = (BaseLoadMoreAdapter) recyclerView.getAdapter();
int lastItemPosition = 0;
int totlacount = recyclerView.getAdapter().getItemCount();
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
lastItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
}
if (layoutManager instanceof GridLayoutManager) {
lastItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
}
if (layoutManager instanceof StaggeredGridLayoutManager) {
int[] lastList = null;
lastList = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
int[] lastVisibleItemPositions = ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(lastList);
for (int i : lastVisibleItemPositions) {
lastItemPosition = i > lastItemPosition ? i : lastItemPosition;
}
}
if (newState == RecyclerView.SCROLL_STATE_IDLE
&& lastItemPosition + 1 == totlacount
&& totlacount >= moreAdapter.getDataSize() + 1) {
if (isRefreshing()) {
//如果正在刷新,則隱藏footer view
moreAdapter.setLoadMoreInvisible();
}
if (moreAdapter.getLoad_status() == STATUS_LOADING
|| moreAdapter.getLoad_status() == STATUS_OVER) {
} else {
if (isRefreshing()) {
//正在刷新不加載
} else {
onLoadMore();
}
}
}
}
示例5: setItems
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@BindingAdapter("items")
public static void setItems(RecyclerView recyclerView, List<HouseItemViewModel> items) {
HouseListAdapter adapter = (HouseListAdapter) recyclerView.getAdapter();
if (adapter != null) {
adapter.setHouseItemViewModels(items);
}else{
adapter = new HouseListAdapter();
adapter.setHouseItemViewModels(items);
recyclerView.setAdapter(adapter);
}
}
示例6: onDraw
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
int dividerLeft = parent.getPaddingLeft()
+ context.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin);
int dividerRight = dividerLeft + divider.getIntrinsicWidth();
int childCount = parent.getChildCount();
int avatarMargin = context.getResources()
.getDimensionPixelSize(R.dimen.account_avatar_margin);
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
int position = parent.getChildAdapterPosition(child);
ThreadAdapter adapter = (ThreadAdapter) parent.getAdapter();
StatusViewData.Concrete current = adapter.getItem(position);
int dividerTop, dividerBottom;
if (current != null) {
StatusViewData.Concrete above = adapter.getItem(position - 1);
if (above != null && above.getId().equals(current.getInReplyToId())) {
dividerTop = child.getTop();
} else {
dividerTop = child.getTop() + avatarMargin;
}
StatusViewData.Concrete below = adapter.getItem(position + 1);
if (below != null && current.getId().equals(below.getInReplyToId()) &&
adapter.getDetailedStatusPosition() != position) {
dividerBottom = child.getBottom();
} else {
dividerBottom = child.getTop() + avatarMargin;
}
divider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
divider.draw(c);
}
}
}
示例7: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* 返回條目之間的間隔,例如我們想仿照ListView一樣添加分割線,那麽就需要設置outRect的下邊距。
* @param outRect
* @param view
* @param parent
* @param state
*/
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int orientation = 0;
int headerCount = 0,footerCount = 0;
if (parent.getAdapter() instanceof XRecyclerViewAdapter){
headerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getHeaderCount();
footerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getFooterCount();
}
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager){
orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
}else if (layoutManager instanceof GridLayoutManager){
orientation = ((GridLayoutManager) layoutManager).getOrientation();
}else if (layoutManager instanceof LinearLayoutManager){
orientation = ((LinearLayoutManager) layoutManager).getOrientation();
}
if (position>=headerCount&&position<parent.getAdapter().getItemCount()-footerCount||mDrawHeaderFooter){
if (orientation == OrientationHelper.VERTICAL){
outRect.bottom = mHeight;
}else {
outRect.right = mHeight;
}
}
}
示例8: onScrolled
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
final int childCount = recyclerView.getChildCount();
if (childCount > 0) {
View lastChild = recyclerView.getChildAt(childCount - 1);
RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
int lastVisible = recyclerView.getChildAdapterPosition(lastChild);
if (lastVisible == outerAdapter.getItemCount() - 1 && hasNextPage() && canLoadNextPage()) {
onLoadNextPage();
}
}
}
示例9: onDraw
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
int visibleCount = parent.getChildCount();
int count = state.getItemCount();
RecyclerView.Adapter adapter = parent.getAdapter();
int adapterCount = adapter != null ? adapter.getItemCount() : 0;
for (int i = 0; i < visibleCount; i++) {
View view = parent.getChildAt(i);
int position = parent.getChildAdapterPosition(view);
float translationX = ViewCompat.getTranslationX(view);
float translationY = ViewCompat.getTranslationY(view);
float alpha = ViewCompat.getAlpha(view);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
int shadows = LEFT|RIGHT;
if(position == count - 1 && adapterCount != 0) shadows|=BOTTOM;
drawable.setAlpha((int) (255*alpha));
drawable.setShadow(shadows);
drawable.setBounds(0, 0, parent.getWidth(), view.getHeight());
int saved = canvas.save();
canvas.translate(parent.getPaddingLeft() + translationX,
view.getTop() + params.topMargin + translationY);
drawable.draw(canvas);
canvas.restoreToCount(saved);
}
}
示例10: getRecyclerViewAdapter
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private BaseRecyclerAdapter getRecyclerViewAdapter(RecyclerView recyclerView) {
if (recyclerView != null) {
RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter instanceof BaseRecyclerAdapter) {
return (BaseRecyclerAdapter) adapter;
} else {
LogUtils.w(RECYCLERVIEW_ADAPTER_WARIN);
}
}
return null;
}
示例11: setContent
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@BindingAdapter("content")
public static <T> void setContent(RecyclerView recyclerView, List<T> content) {
RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter == null) {
return;
}
if (adapter instanceof BookListAdapter) {
((BookListAdapter) adapter).replace((List<Book>) content);
}
}
示例12: RecyclerIndex
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public RecyclerIndex(RecyclerView recyclerView) {
super();
this.recyclerView = recyclerView;
adapter = recyclerView.getAdapter();
if (adapter == null) {
throw new IllegalStateException("You must be set adapter be for use index!");
}
}
示例13: onMove
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
// 不同Type之間不可移動
if (viewHolder.getItemViewType() != target.getItemViewType()) {
return false;
}
if (recyclerView.getAdapter() instanceof OnItemMoveListener) {
OnItemMoveListener listener = ((OnItemMoveListener) recyclerView.getAdapter());
listener.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
}
return true;
}
示例14: setMovies
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@BindingAdapter("bind:movies")
public static void setMovies(RecyclerView recyclerView, List<Movie> movies) {
RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter != null && adapter instanceof MovieAdapter) {
((MovieAdapter) adapter).setMovies(movies);
} else {
throw new IllegalStateException("RecyclerView either has no adapter set or the "
+ "adapter isn't of type MovieAdapter");
}
}
示例15: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int orientation = 0;
int headerCount = 0,footerCount = 0;
if (parent.getAdapter() instanceof RecyclerArrayAdapter){
headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
}
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager){
orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
}else if (layoutManager instanceof GridLayoutManager){
orientation = ((GridLayoutManager) layoutManager).getOrientation();
}else if (layoutManager instanceof LinearLayoutManager){
orientation = ((LinearLayoutManager) layoutManager).getOrientation();
}
if (position>=headerCount&&position<parent.getAdapter().getItemCount()-footerCount||mDrawHeaderFooter){
if (orientation == OrientationHelper.VERTICAL){
outRect.bottom = mHeight;
}else {
outRect.right = mHeight;
}
}
}