com.zhy.adapter.recyclerview.base.ViewHolder Java Examples

The following examples show how to use com.zhy.adapter.recyclerview.base.ViewHolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecyclerViewActivity.java    From ViewCapture with Apache License 2.0 6 votes vote down vote up
private void setRecycleView(int type) {
    switch (type) {
        case 0:
            recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
            break;
        case 1:
            recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
            break;
        case 2:
            recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
            break;
    }
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(new CommonAdapter<String>(this, R.layout.layout_item, //
              Arrays.asList(getResources().getStringArray(R.array.listView_item))) {
        @Override
        protected void convert(ViewHolder holder, String s, int position) {
            ((TextView) holder.getView(R.id.tv)).setText(s);
        }
    });
}
 
Example #2
Source File: OtherStoriesHeaderDelegate.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
@Override
public void convert(ViewHolder holder, BaseItem baseItem, int position) {
    OtherStoriesHeader storiesHeader = (OtherStoriesHeader) baseItem;
    ImageView imageView = holder.getView(R.id.image);
    TextView textView = holder.getView(R.id.title);
    if ((boolean) SharedPreferencesUtils.get(App.getContext(), "NO_IMAGE_MODE", false)
            && !NetWorkUtils.isWifiConnected(App.getContext())) {
        Glide.with(holder.getConvertView().getContext())
                .load(R.drawable.image_top_default)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .centerCrop()
                .into(imageView);
    } else {
        Glide.with(holder.getConvertView().getContext())
                .load(storiesHeader.getUrl())
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .centerCrop()
                .into(imageView);
    }
    textView.setText(storiesHeader.getDescription());
}
 
Example #3
Source File: LoadmoreWrapper.java    From baseAdapter with Apache License 2.0 6 votes vote down vote up
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
    if (viewType == ITEM_TYPE_LOAD_MORE)
    {
        ViewHolder holder;
        if (mLoadMoreView != null)
        {
            holder = ViewHolder.createViewHolder(parent.getContext(), mLoadMoreView);
        } else
        {
            holder = ViewHolder.createViewHolder(parent.getContext(), parent, mLoadMoreLayoutId);
        }
        return holder;
    }
    return mInnerAdapter.onCreateViewHolder(parent, viewType);
}
 
Example #4
Source File: CouponDashLineFragment.java    From CouponView with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    int[] intArray = getResources().getIntArray(R.array.colors);
    list.clear();
    for (int anIntArray : intArray) {
        list.add(anIntArray);
    }
    commonAdapter = new CommonAdapter<Integer>(getActivity(), R.layout.item_coupon_dash_line, list) {
        @Override
        protected void convert(ViewHolder holder, Integer s, int position) {
            CouponView couponView = holder.getView(R.id.couponView);
            couponView.setBackgroundColor(s);
        }
    };
    mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
            outRect.set(dp2Px(6), dp2Px(6), dp2Px(6), 0);
        }
    });
    mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
    mRecyclerView.setAdapter(commonAdapter);
}
 
Example #5
Source File: EmptyWrapper.java    From baseAdapter with Apache License 2.0 6 votes vote down vote up
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
    if (isEmpty())
    {
        ViewHolder holder;
        if (mEmptyView != null)
        {
            holder = ViewHolder.createViewHolder(parent.getContext(), mEmptyView);
        } else
        {
            holder = ViewHolder.createViewHolder(parent.getContext(), parent, mEmptyLayoutId);
        }
        return holder;
    }
    return mInnerAdapter.onCreateViewHolder(parent, viewType);
}
 
Example #6
Source File: CommentItemDelegate.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
@Override
public void convert(ViewHolder holder, BaseItem baseItem, int position) {
    Context context = holder.getConvertView().getContext();
    StoryContentComment comment = (StoryContentComment) baseItem;
    if ((boolean) SharedPreferencesUtils.get(App.getContext(), "NO_IMAGE_MODE", false)
            && !NetWorkUtils.isWifiConnected(App.getContext())) {
        Glide.with(context)
                .load(R.drawable.account_avatar)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .transform(new CircleTransform(context))
                .into((ImageView) holder.getView(R.id.avatar));
    } else {
        Glide.with(context)
                .load(comment.getAvatar())
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .transform(new CircleTransform(context))
                .into((ImageView) holder.getView(R.id.avatar));
    }
    holder.setText(R.id.author, comment.getAuthor());
    holder.setText(R.id.content, comment.getContent());
    holder.setText(R.id.likes, Integer.toString(comment.getLikes()));
    holder.setText(R.id.time, comment.getTime());
}
 
Example #7
Source File: EditorItemDelegate.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
@Override
public void convert(ViewHolder holder, BaseItem baseItem, int position) {
    Context context = holder.getConvertView().getContext();
    Editors editors = (Editors) baseItem;
    ((TextView) holder.getView(R.id.editor_name)).setText(editors.getName());
    ((TextView) holder.getView(R.id.editor_bio)).setText(editors.getBio());
    if ((boolean) SharedPreferencesUtils.get(App.getContext(), "NO_IMAGE_MODE", false)
            && !NetWorkUtils.isWifiConnected(App.getContext())) {
        Glide.with(context)
                .load(R.drawable.editor_profile_avatar)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .transform(new CircleTransform(context))
                .into((ImageView) holder.getView(R.id.editor_avatar));
    } else {
        Glide.with(context)
                .load(editors.getAvatar())
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .transform(new CircleTransform(context))
                .into((ImageView) holder.getView(R.id.editor_avatar));
    }
}
 
Example #8
Source File: CouponCombinationFragment.java    From CouponView with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    int[] intArray = getResources().getIntArray(R.array.colors);
    list.clear();
    for (int anIntArray : intArray) {
        list.add(anIntArray);
    }
    commonAdapter = new CommonAdapter<Integer>(getActivity(), R.layout.item_coupon_combination, list) {
        @Override
        protected void convert(ViewHolder holder, Integer s, int position) {
            CouponView couponView = holder.getView(R.id.couponView);
            couponView.setBackgroundColor(s);
        }
    };
    mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
            outRect.set(dp2Px(6), dp2Px(6), dp2Px(6), 0);
        }
    });
    mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
    mRecyclerView.setAdapter(commonAdapter);
}
 
Example #9
Source File: BaseLiveWraperFragment.java    From likequanmintv with Apache License 2.0 6 votes vote down vote up
@Override
protected void convertItem(ViewHolder holder, final PlayBean playBean, int position) {
    holder.setImageUrl(R.id.thumnails,playBean.thumb,new GlideRoundTransform(mActivity,5));
    holder.setText(R.id.title,playBean.title);
    holder.setText(R.id.tv_viewnum,playBean.view);
    holder.setText(R.id.nickName,playBean.nick);
    holder.setImageUrl(R.id.ic_head,playBean.avatar,new GlideCircleTransform(mActivity));
    holder.getItemView().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent =new Intent(mActivity, CommonLiveUI.class);
            intent.putExtra("playBean",playBean);
            getActivity().startActivity(intent);
            getActivity().overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
        }
    });
}
 
Example #10
Source File: EmptyWrapper.java    From likequanmintv with Apache License 2.0 6 votes vote down vote up
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
    if (isEmpty())
    {
        ViewHolder holder;
        if (mEmptyView != null)
        {
            holder = ViewHolder.createViewHolder(parent.getContext(), mEmptyView);
        } else
        {
            holder = ViewHolder.createViewHolder(parent.getContext(), parent, mEmptyLayoutId);
        }
        return holder;
    }
    return mInnerAdapter.onCreateViewHolder(parent, viewType);
}
 
Example #11
Source File: LoadMoreCommonAdapter.java    From likequanmintv with Apache License 2.0 6 votes vote down vote up
@Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
//        Log.d("LoadMoreCommonAdapter","onCreateViewHolder");
        if (viewType == ITEM_TYPE_LOAD_MORE)
        {
            ViewHolder holder;
            if (mLoadMoreView != null)
            {
                holder = ViewHolder.createViewHolder(parent.getContext(), mLoadMoreView);
            } else
            {
                holder = ViewHolder.createViewHolder(parent.getContext(), parent, mLoadMoreLayoutId);
            }
            return holder;
        }
        return super.onCreateViewHolder(parent, viewType);
    }
 
Example #12
Source File: LoadMoreWrapper.java    From likequanmintv with Apache License 2.0 6 votes vote down vote up
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
    if (viewType == ITEM_TYPE_LOAD_MORE)
    {
        ViewHolder holder;
        if (mLoadMoreView != null)
        {
            holder = ViewHolder.createViewHolder(parent.getContext(), mLoadMoreView);
        } else
        {
            holder = ViewHolder.createViewHolder(parent.getContext(), parent, mLoadMoreLayoutId);
        }
        return holder;
    }
    return mInnerAdapter.onCreateViewHolder(parent, viewType);
}
 
Example #13
Source File: LoveLiveListFragment.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
protected void convertItem(ViewHolder holder, final PlayBean playBean, int position) {
    holder.setImageUrl(R.id.thumnails,playBean.thumb,new GlideRoundTransform(mActivity,5));
    holder.setText(R.id.tv_viewnum,playBean.view);
    holder.setText(R.id.intro,playBean.title);
    holder.getItemView().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent =new Intent(mActivity, VerFullLiveUI.class);
            intent.putExtra("playBean",playBean);
            getActivity().startActivity(intent);
            getActivity().overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
        }
    });
}
 
Example #14
Source File: FileChooserActivity.java    From Mp3Cutter with GNU General Public License v3.0 5 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            android.transition.Transition transition = TransitionInflater.from(this).inflateTransition(R.transition.explode);
            getWindow().setEnterTransition(transition);
        }
        StatusBarUtil.setColor(this, Color.TRANSPARENT);
        mDataBinding.btnUpdate.setOnClickListener(this);
        mDataBinding.btnUpdate.measure(0, 0);
        mUpdateBtnLeft = ScreenUtils.getScreenSize(this)[0] -
                mDataBinding.btnUpdate.getMeasuredWidth() - DensityUtils.dp2px(this ,10);
        initToolbar();
        mDataBinding.rlMusice.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new CommonAdapter<MusicInfo>(this, R.layout.item_musicfile, mMusicList) {
            @Override
            protected void convert(ViewHolder holder, final MusicInfo musicInfo, int position) {
                holder.setText(R.id.tv_name, musicInfo.getTitle());
                holder.setText(R.id.tv_size, FileUtils.formetFileSize(musicInfo.getFileSize()));
                if(TextUtils.isEmpty(musicInfo.getCoverPath())){
                    holder.setImageDrawable(R.id.iv_icon, getResources().getDrawable(R.mipmap.music_icon));
                }
                else {
                    RequestOptions options = new RequestOptions().placeholder(R.mipmap.music_icon);
                    Glide.with(FileChooserActivity.this).load(musicInfo.getCoverPath())
                            .apply(options).into((ImageView) holder.getView(R.id.iv_icon));
                }
//                holder.setImageBitmap(R.id.iv_icon, CoverLoader.getInstance().loadThumbnail(musicInfo));
                holder.itemView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        clickItem(musicInfo);
                    }
                });
            }
        };
        mDataBinding.rlMusice.setAdapter(mAdapter);
        mDataBinding.rlMusice.addItemDecoration(new DividerItemDecoration(this,
                DividerItemDecoration.VERTICAL));
        FileChooserActivityPermissionsDispatcher.refreshDataWithPermissionCheck(this, false);
    }
 
Example #15
Source File: MsgSendItemDelagate.java    From baseAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void convert(ViewHolder holder, ChatMessage chatMessage, int position)
{
    holder.setText(R.id.chat_send_content, chatMessage.getContent());
    holder.setText(R.id.chat_send_name, chatMessage.getName());
    holder.setImageResource(R.id.chat_send_icon, chatMessage.getIcon());
}
 
Example #16
Source File: EmptyWrapper.java    From baseAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
    if (isEmpty())
    {
        return;
    }
    mInnerAdapter.onBindViewHolder(holder, position);
}
 
Example #17
Source File: MsgComingItemDelagate.java    From baseAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void convert(ViewHolder holder, ChatMessage chatMessage, int position)
{
    holder.setText(R.id.chat_from_content, chatMessage.getContent());
    holder.setText(R.id.chat_from_name, chatMessage.getName());
    holder.setImageResource(R.id.chat_from_icon, chatMessage.getIcon());
}
 
Example #18
Source File: MultiItemTypeAdapter.java    From baseAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    ItemViewDelegate itemViewDelegate = mItemViewDelegateManager.getItemViewDelegate(viewType);
    int layoutId = itemViewDelegate.getItemViewLayoutId();
    ViewHolder holder = ViewHolder.createViewHolder(mContext, parent, layoutId);
    onViewHolderCreated(holder,holder.getConvertView());
    setListener(parent, holder, viewType);
    return holder;
}
 
Example #19
Source File: ColumnFragmentListAdapter.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
    protected void convert(ViewHolder holder, final ItemColumn itemColumn, int position) {
//
        holder.setText(R.id.name,itemColumn.name);
        holder.setImageUrl(R.id.thumnails,itemColumn.image,new GlideRoundTransform(mContext,1.5f));

        holder.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mActivity, ColumnListActivity.class);
                intent.putExtra("itemColumn",itemColumn);
                mActivity.startActivity(intent);
            }
        });
    }
 
Example #20
Source File: LoadMoreWrapper.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
    if (isShowLoadMore(position))
    {
        if (mOnLoadMoreListener != null)
        {
            mOnLoadMoreListener.onLoadMoreRequested();
        }
        return;
    }
    mInnerAdapter.onBindViewHolder(holder, position);
}
 
Example #21
Source File: BaseListFragment.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
protected void initView(View rootView) {
    mRv=find(R.id.mRv);
    mRv.setLayoutManager(new GridLayoutManager(mActivity,2));
    adapter= new LoadMoreCommonAdapter<T>(mActivity, this.getListItemLayout()) {
        @Override
        protected void convert(ViewHolder holder, T t, int position) {
            convertItem(holder,t,position);
        }
    };
    mRv.setAdapter(adapter);
}
 
Example #22
Source File: LoadMoreCommonAdapter.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
private void setFullSpan(RecyclerView.ViewHolder holder)
{
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

    if (lp != null
            && lp instanceof StaggeredGridLayoutManager.LayoutParams)
    {
        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;

        p.setFullSpan(true);
    }
}
 
Example #23
Source File: LoadMoreCommonAdapter.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
    public void onViewAttachedToWindow(ViewHolder holder)
    {
//        Log.d("LoadMoreCommonAdapter","onViewAttachedToWindow");

        if (isShowLoadMore(holder.getLayoutPosition()))
        {
            setFullSpan(holder);
        }
    }
 
Example #24
Source File: LoadMoreCommonAdapter.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
    public void onBindViewHolder(ViewHolder holder, int position)
    {
//        Log.d("LoadMoreCommonAdapter","onBindViewHolder");
        if (isShowLoadMore(position))
        {
            if (mOnLoadMoreListener != null)
            {
                mOnLoadMoreListener.onLoadMoreRequested();
            }
            return;
        }
        super.onBindViewHolder(holder, position);
    }
 
Example #25
Source File: LoadmoreWrapper.java    From baseAdapter with Apache License 2.0 5 votes vote down vote up
private void setFullSpan(RecyclerView.ViewHolder holder)
{
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

    if (lp != null
            && lp instanceof StaggeredGridLayoutManager.LayoutParams)
    {
        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;

        p.setFullSpan(true);
    }
}
 
Example #26
Source File: LoadMoreWrapper.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
private void setFullSpan(RecyclerView.ViewHolder holder)
{
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

    if (lp != null
            && lp instanceof StaggeredGridLayoutManager.LayoutParams)
    {
        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;

        p.setFullSpan(true);
    }
}
 
Example #27
Source File: LoadMoreWrapper.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
{
    mInnerAdapter.onViewAttachedToWindow(holder);

    if (isShowLoadMore(holder.getLayoutPosition()))
    {
        setFullSpan(holder);
    }
}
 
Example #28
Source File: HeaderAndFooterWrapper.java    From baseAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
    if (isHeaderViewPos(position))
    {
        return;
    }
    if (isFooterViewPos(position))
    {
        return;
    }
    mInnerAdapter.onBindViewHolder(holder, position - getHeadersCount());
}
 
Example #29
Source File: HeaderAndFooterWrapper.java    From baseAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
{
    mInnerAdapter.onViewAttachedToWindow(holder);
    int position = holder.getLayoutPosition();
    if (isHeaderViewPos(position) || isFooterViewPos(position))
    {
        WrapperUtils.setFullSpan(holder);
    }
}
 
Example #30
Source File: LoadmoreWrapper.java    From baseAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
{
    mInnerAdapter.onViewAttachedToWindow(holder);

    if (isShowLoadMore(holder.getLayoutPosition()))
    {
        setFullSpan(holder);
    }
}