Java Code Examples for com.chad.library.adapter.base.BaseViewHolder#getItemViewType()
The following examples show how to use
com.chad.library.adapter.base.BaseViewHolder#getItemViewType() .
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: StockAdapter.java From PinnedSectionItemDecoration with Apache License 2.0 | 6 votes |
@Override protected void convert(BaseViewHolder holder, StockEntity.StockInfo item) { switch (holder.getItemViewType()) { case StockEntity.StockInfo.TYPE_HEADER: holder.setText(R.id.tv_stock_name, item.pinnedHeaderName).addOnClickListener(R.id.checkbox).setChecked(R.id.checkbox, item.check); break; case StockEntity.StockInfo.TYPE_DATA: final String stockNameAndCode = item.stock_name + "\n" + item.stock_code; SpannableStringBuilder ssb = new SpannableStringBuilder(stockNameAndCode); ssb.setSpan(new ForegroundColorSpan(Color.parseColor("#a4a4a7")), item.stock_name.length(), stockNameAndCode.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new AbsoluteSizeSpan(StockActivity.dip2px(holder.itemView.getContext(), 13)), item.stock_name.length(), stockNameAndCode.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); holder.setText(R.id.tv_stock_name_code, ssb).setText(R.id.tv_current_price, item.current_price) .setText(R.id.tv_rate, (item.rate < 0 ? String.format("%.2f", item.rate) : "+" + String.format("%.2f", item.rate)) + "%"); break; } }
Example 2
Source File: ShopCartLikeAdapter.java From FastWaiMai with MIT License | 6 votes |
@Override protected void convert(BaseViewHolder helper, MultipleItemEntity entity) { switch (helper.getItemViewType()) { case ShopCartItemType.SHOP_YOU_LIKE: final String name = entity.getField(MultipleFields.TEXT); final String spec = entity.getField(MultipleFields.SPEC); final String price = entity.getField(ShopCartItemFields.PRICE); final String originPrice = entity.getField(ShopCartItemFields.ORIGIN_PRICE); final String thumb = entity.getField(MultipleFields.IMAGE_URL); helper.setText(R.id.tv_like_name, name); helper.setText(R.id.tv_like_spec, spec); helper.setText(R.id.tv_like_price, price); helper.setText(R.id.tv_like_origin_price, originPrice); final ImageView imageView = helper.getView(R.id.iv_like_img); Glide.with(mContext) .load(thumb) .apply(OPTIONS) .into(imageView); break; default: break; } }
Example 3
Source File: ExpandableCommentItemAdapter.java From HaiNaBaiChuan with Apache License 2.0 | 6 votes |
@Override protected void convert(final BaseViewHolder holder, final MultiItemEntity item) { switch (holder.getItemViewType()) { case TYPE_LEVEL_0: final CommentFill commentFill = (CommentFill) item; final Comment comment = commentFill.getComment(); holder.setText(R.id.tvNickname, comment.getUser().getNickname()) .setText(R.id.tvDate, comment.getCreatedAt()) .setText(R.id.tvComment, comment.getContent()); holder.addOnClickListener(R.id.btnReply) .addOnClickListener(R.id.imgHead); ImageView head = holder.getView(R.id.imgHead); ImgLoadUtil.loadHead(mContext, head, comment.getUser().getHeadPic()); expandAll(holder.getAdapterPosition(), true); break; case TYPE_LEVEL_1: final Reply reply = ((ReplyFill) item).getReply(); holder.setText(R.id.tvReplyUser, reply.getSpeakUser().getNickname() + " ") .setText(R.id.tvReplyWho, reply.getReplyUser().getNickname()) .setText(R.id.tvReply, reply.getContent()); holder.addOnClickListener(R.id.tvReplyUser) .addOnClickListener(R.id.tvReplyWho); break; } }
Example 4
Source File: DiscountAdapter.java From FastWaiMai with MIT License | 6 votes |
@Override protected void convert(BaseViewHolder helper, MultipleItemEntity item) { switch (helper.getItemViewType()){ case DiscountCardItemType.ITEM_NORMAL_AVAILIABLE: String shopName = item.getField(DiscountItemFields.SHOP_NAME); helper.setText(R.id.tv_item_discount_shopname, shopName); String type = item.getField(DiscountItemFields.TYPE); helper.setText(R.id.tv_item_discount_type, type); String expireTime = item.getField(DiscountItemFields.EXPIRE_TIME); helper.setText(R.id.tv_item_discount_expiretime, "有效期至" + expireTime); String orimoney = item.getField(DiscountItemFields.MONEY); final SpannableString money = new SpannableString(orimoney); money.setSpan(new AbsoluteSizeSpan(13, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); helper.setText(R.id.tv_item_discount_money, money); String condition = item.getField(DiscountItemFields.CONDITION); helper.setText(R.id.tv_item_discount_condition, condition); break; case DiscountCardItemType.ITEM_NORMAL_UNAVAILIABLE: break; default: break; } }
Example 5
Source File: PickArrivalTimeDialog.java From FastWaiMai with MIT License | 6 votes |
@Override protected void convert(BaseViewHolder helper, MultipleItemEntity item) { switch (helper.getItemViewType()) { case ITEM_ARRIVAL_TIME_NORMAL: final TextView timeView = helper.getView(R.id.tv_item_arrival_time); timeView.setText((String)item.getField(ARRIVAL_TIME_TIME)); final TextView moneyView = helper.getView(R.id.tv_item_arrival_distribution_money); final ImageView choosedView = helper.getView(R.id.iv_item_arrival_flag); moneyView.setText(String.format("%s%s", item.getField(ARRIVAL_TIME_MONEY), getContext().getString(R.string.currency_suffix))); boolean choosed = item.getField(MultipleFields.TAG); if(choosed){ choosedView.setVisibility(View.VISIBLE); timeView.setTextColor(Color.BLUE); moneyView.setTextColor(Color.BLUE); }else{ choosedView.setVisibility(View.INVISIBLE); timeView.setTextColor(Color.BLACK); moneyView.setTextColor(Color.BLACK); } break; default: break; } }
Example 6
Source File: OpenAPISAdapter.java From WanAndroid with GNU General Public License v3.0 | 6 votes |
@Override protected void convert(BaseViewHolder helper, MultiItemEntity item) { switch (helper.getItemViewType()) { case TYPE_SECTION: ThreeAPIBean threeAPIBean = (ThreeAPIBean) item; ItemOpenApiSectionBinding binding = (ItemOpenApiSectionBinding) helper.itemView.getTag(com.xujiaji.mvvmquick.R.id.BaseQuickAdapter_databinding_support); binding.setThreeAPIBean(threeAPIBean); helper.itemView.setOnClickListener(v -> { int pos = helper.getAdapterPosition(); if (threeAPIBean.isExpanded()) { collapse(pos); } else { expand(pos); } }); break; case TYPE_API: ThreeAPIBean.LinkBean linkBean = (ThreeAPIBean.LinkBean) item; ItemOpenApiBinding b = (ItemOpenApiBinding) helper.itemView.getTag(com.xujiaji.mvvmquick.R.id.BaseQuickAdapter_databinding_support); b.setLinkBean(linkBean); break; } }
Example 7
Source File: Forum9PornIndexAdapter.java From v9porn with MIT License | 5 votes |
@Override protected void convert(BaseViewHolder helper, PinnedHeaderEntity<F9PronItem> item) { switch (helper.getItemViewType()) { case TYPE_HEADER: helper.setText(R.id.tv_item_forum_91_porn_section_header_title, item.getPinnedHeaderName()); break; case TYPE_DATA: helper.setText(R.id.tv_item_forum_91_porn_title, item.getData().getTitle()); helper.setText(R.id.tv_item_forum_91_porn_author_publish_time, item.getData().getAuthor() + "\n" + item.getData().getAuthorPublishTime()); helper.setText(R.id.tv_item_forum_91_porn_reply_view, item.getData().getReplyCount() + "/" + item.getData().getViewCount()); helper.setText(R.id.tv_item_forum_91_porn_last_post_author_time, item.getData().getLastPostAuthor() + "\n" + item.getData().getLastPostTime()); break; default: } }
Example 8
Source File: HomeRecyclerViewAdapter.java From MVP-Dagger2-Rxjava-Retrofit with Apache License 2.0 | 5 votes |
@Override protected void convert(BaseViewHolder helper, HomeEntity item) { switch (helper.getItemViewType()) { case HomeEntity.TYPE_1: setData(helper, item); break; case HomeEntity.TYPE_2: break; case HomeEntity.TYPE_3: break; } }
Example 9
Source File: GankAdapter.java From Ency with Apache License 2.0 | 5 votes |
@Override protected void convert(BaseViewHolder helper, GankBean.ResultsBean item) { switch (helper.getItemViewType()) { case GankBean.ResultsBean.TEXT: helper.setText(R.id.txt_gank_title, item.getDesc()); helper.setText(R.id.txt_gank_author, item.getSource()); helper.setText(R.id.txt_gank_time, item.getPublishedAt().substring(0, 10)); break; case GankBean.ResultsBean.IMG: helper.setText(R.id.txt_gank_title, item.getDesc()); helper.setText(R.id.txt_gank_author, item.getSource()); helper.setText(R.id.txt_gank_time, item.getPublishedAt().substring(0, 10)); ViewPager viewPager = helper.getView(R.id.viewpager_gank_img); ImageAdapter adapter = new ImageAdapter(mContext, item.getImages(),isPTP); viewPager.setAdapter(adapter); break; case GankBean.ResultsBean.MEIZI: // ImageView imageView = helper.getView(R.id.img_meizi); // GlideApp.with(mContext) // .load(item.getUrl()) // .priority(Priority.LOW) // .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) // .override(Target.SIZE_ORIGINAL) // .into(imageView); break; } }
Example 10
Source File: GankIoCustomAdapter.java From YiZhi with Apache License 2.0 | 5 votes |
@Override protected void convert(BaseViewHolder helper, GankIoCustomItemBean item) { initTypeImage(helper, item); helper.setText(R.id.tv_item_who, StringUtils.isEmpty(item.getWho()) ? "佚名" : item .getWho()); helper.setText(R.id.tv_item_type, item.getType()); helper.setText(R.id.tv_item_time, item.getCreatedAt().substring(0, 10)); switch (helper.getItemViewType()) { case GankIoCustomItemBean.GANK_IO_DAY_ITEM_CUSTOM_NORMAL: helper.setText(R.id.tv_item_title, item.getDesc()); initTitleColor(helper, item); if (item.getImages() != null) { if (item.getImages().size() > 0 && !TextUtils.isEmpty(item.getImages().get(0))) Glide.with(mContext).load(item.getImages().get(0) + mImageSize) .asBitmap() .into((ImageView) helper.getView(R.id.iv_item_image)); } break; case GankIoCustomItemBean.GANK_IO_DAY_ITEM_CUSTOM_IMAGE: Glide.with(mContext) .load(item.getUrl()) .asBitmap() .centerCrop() .placeholder(R.mipmap.img_default_meizi) .into((ImageView) helper.getView(R.id.iv_item_image)); break; case GankIoCustomItemBean.GANK_IO_DAY_ITEM_CUSTOM_NO_IMAGE: helper.setText(R.id.tv_item_title, item.getDesc()); initTitleColor(helper, item); break; default: break; } }
Example 11
Source File: Forum9PornIndexAdapter.java From v9porn with MIT License | 5 votes |
@Override protected void convert(BaseViewHolder helper, PinnedHeaderEntity<F9PronItem> item) { switch (helper.getItemViewType()) { case TYPE_HEADER: helper.setText(R.id.tv_item_forum_91_porn_section_header_title, item.getPinnedHeaderName()); break; case TYPE_DATA: helper.setText(R.id.tv_item_forum_91_porn_title, item.getData().getTitle()); helper.setText(R.id.tv_item_forum_91_porn_author_publish_time, item.getData().getAuthor() + "\n" + item.getData().getAuthorPublishTime()); helper.setText(R.id.tv_item_forum_91_porn_reply_view, item.getData().getReplyCount() + "/" + item.getData().getViewCount()); helper.setText(R.id.tv_item_forum_91_porn_last_post_author_time, item.getData().getLastPostAuthor() + "\n" + item.getData().getLastPostTime()); break; default: } }
Example 12
Source File: CollectionListAdapter.java From Focus with GNU General Public License v3.0 | 5 votes |
@Override protected void convert(BaseViewHolder helper, Collection item) { switch (helper.getItemViewType()) { case Collection.FEED_ITEM: //文章item helper.setText(R.id.post_title,item.getTitle()); helper.setText(R.id.rss_name,item.getFeedName()); helper.setText(R.id.post_summay, DataUtil.getOptimizedDesc(item.getSummary())); helper.setText(R.id.post_time, DateUtil.getTTimeStringByInt(item.getDate())); if (UserPreference.queryValueByKey(UserPreference.not_show_image_in_list,"0").equals("0")){ String imageUrl = DataUtil.getCollectionItemImageUrl(item); if (!StringUtil.trim(imageUrl).equals("")){ if (!imageUrl.startsWith("http://")&& !imageUrl.startsWith("https://")){ //说明是相对地址 if (!imageUrl.substring(0,1).equals("/")){ imageUrl = "/" + imageUrl;//前面如果没有/,补足一个 } imageUrl = StringUtil.getUrlPrefix(item.getUrl()) + imageUrl; } helper.getView(R.id.post_pic).setVisibility(View.VISIBLE); ImageLoader.getInstance().displayImage(StringUtil.trim(imageUrl), (ImageView) helper.getView(R.id.post_pic), ImageLoaderManager.getSubsciptionIconOptions(activity)); }else { helper.getView(R.id.post_pic).setVisibility(View.GONE); } }else {//无图列表 helper.getView(R.id.post_pic).setVisibility(View.GONE); } initListener(helper,item); break; case Collection.WEBSITE: // break; } }
Example 13
Source File: OrderListAdapter.java From FastWaiMai with MIT License | 5 votes |
@Override protected void convert(BaseViewHolder helper, MultipleItemEntity item) { switch (helper.getItemViewType()){ case OrderListItemType.ITEM_ORDER_LIST_HEADER: //订单ID String orderId = item.getField(OrderItemFields.ORDER_ID); //创建时间 String createTime = item.getField(OrderItemFields.CREATE_TIME); //订单状态 String orderStatus = item.getField(OrderItemFields.PAY_STATE); final AppCompatTextView orderIdView = helper.getView(R.id.tv_item_allorder_orderid); helper.setText(R.id.tv_item_allorder_state, orderStatus); //helper.setText(R.id.tv_item_allorder_createtime, createTime); orderIdView.setText(String.valueOf("订单编号:"+orderId)); break; case OrderListItemType.ITEM_ORDER_LIST_CONTENT: final String goodsName = item.getField(OrderItemFields.PRODUCT_NAME); final String goodsPic = item.getField(OrderItemFields.PRODUCT_IMG); final double goodsPrice = item.getField(OrderItemFields.PRODUCT_PRICE); final int count = item.getField(OrderItemFields.PRODUCT_COUNT); helper.setText(R.id.tv_item_allorder_title, goodsName); helper.setText(R.id.tv_item_allorder_item_num, "共"+count+"件"); helper.setText(R.id.tv_item_allorder_item_price, goodsPrice+""); final AppCompatImageView imgThumb = helper.getView(R.id.iv_item_allorder_pic); Glide.with(mContext) .load(goodsPic) .apply(OPTIONS) .into(imgThumb); break; case OrderListItemType.ITEM_ORDER_LIST_FOOTER: final Double totalPrice = item.getField(OrderItemFields.TOTAL_PRICE); helper.setText(R.id.tv_item_allorder_total, totalPrice+""); break; default: break; } }
Example 14
Source File: CollectionListAdapter.java From Focus with GNU General Public License v3.0 | 5 votes |
@Override protected void convert(BaseViewHolder helper, Collection item) { switch (helper.getItemViewType()) { case Collection.FEED_ITEM: //文章item helper.setText(R.id.post_title,item.getTitle()); helper.setText(R.id.rss_name,item.getFeedName()); helper.setText(R.id.post_summay, DataUtil.getOptimizedDesc(item.getSummary())); helper.setText(R.id.post_time, DateUtil.getTTimeStringByInt(item.getDate())); if (UserPreference.queryValueByKey(UserPreference.not_show_image_in_list,"0").equals("0")){ String imageUrl = DataUtil.getCollectionItemImageUrl(item); if (!StringUtil.trim(imageUrl).equals("")){ if (!imageUrl.startsWith("http://")&& !imageUrl.startsWith("https://")){ //说明是相对地址 if (!imageUrl.substring(0,1).equals("/")){ imageUrl = "/" + imageUrl;//前面如果没有/,补足一个 } imageUrl = StringUtil.getUrlPrefix(item.getUrl()) + imageUrl; } helper.getView(R.id.post_pic).setVisibility(View.VISIBLE); ImageLoader.getInstance().displayImage(StringUtil.trim(imageUrl), (ImageView) helper.getView(R.id.post_pic), ImageLoaderManager.getSubsciptionIconOptions(activity)); }else { helper.getView(R.id.post_pic).setVisibility(View.GONE); } }else {//无图列表 helper.getView(R.id.post_pic).setVisibility(View.GONE); } initListener(helper,item); break; case Collection.WEBSITE: // break; } }
Example 15
Source File: GankIoDayAdapter.java From YiZhi with Apache License 2.0 | 4 votes |
@Override protected void convert(BaseViewHolder helper, GankIoDayItemBean item) { helper.setText(R.id.tv_type_item_title, item.getType()); helper.setText(R.id.tv_item_title, item.getDesc()); switch (item.getType()) { case "福利": helper.setImageResource(R.id.iv_type_item_title, R.drawable .ic_vector_title_welfare); Glide.with(mContext).load(item.getUrl()).crossFade().into((ImageView) helper .getView(R.id.iv_item_title)); break; case "Android": helper.setImageResource(R.id.iv_type_item_title, R.drawable .ic_vector_title_android); helper.setImageResource(R.id.iv_item_title, mResAndroid[mAndroidIndex % 6]); break; case "iOS": helper.setImageResource(R.id.iv_type_item_title, R.drawable.ic_vector_title_ios); helper.setImageResource(R.id.iv_item_title, mResIOS[mIOSIndex % 3]); break; case "前端": helper.setImageResource(R.id.iv_type_item_title, R.drawable.ic_vector_title_front); helper.setImageResource(R.id.iv_item_title, R.mipmap.gank_io_day_item_web); break; case "休息视频": helper.setImageResource(R.id.iv_type_item_title, R.drawable.ic_vector_title_video); helper.setImageResource(R.id.iv_item_title, R.mipmap.gank_io_day_item_video); break; case "瞎推荐": helper.setImageResource(R.id.iv_type_item_title, R.drawable.ic_vector_item_tuijian); break; case "拓展资源": helper.setImageResource(R.id.iv_type_item_title, R.drawable.ic_vector_item_tuozhan); break; case "App": helper.setImageResource(R.id.iv_type_item_title, R.drawable.ic_vector_item_app); break; } switch (helper.getItemViewType()) { case GankIoDayItemBean.GANK_IO_DAY_ITEM_DAY_NORMAL: helper.addOnClickListener(R.id.ll_more); break; case GankIoDayItemBean.GANK_IO_DAY_ITEM_DAY_REFESH: helper.addOnClickListener(R.id.ll_more).addOnClickListener(R.id.ll_refesh); break; default: break; } //GankIo 返回数据中,很多没有images,这里不用GankIo的图,直接写死 // if(item.getImages() == null) // return; // // Glide.with(mContext).load(item.getImages().get(0)).crossFade().into((ImageView) // helper.getView(R.id.iv_item_title)); }
Example 16
Source File: SectionAdapter.java From FastWaiMai with MIT License | 4 votes |
@Override protected void convert(final BaseViewHolder helper, MultipleItemEntity item) { switch (helper.getItemViewType()){ case ContentItemType.ITEM_NORMAL: final String goodsName = item.getField(MultipleFields.TEXT); final String goodsSpec = item.getField(MultipleFields.SPEC); final String goodsThumb = item.getField(MultipleFields.IMAGE_URL); final String price = item.getField(ShopCartItemFields.PRICE); final String originPrice = item.getField(ShopCartItemFields.ORIGIN_PRICE); //设置Text helper.setText(R.id.tv_goods_name, goodsName); helper.setText(R.id.tv_goods_detail, goodsSpec); helper.setText(R.id.tv_price, "¥" + price); final TextView originPriceView = helper.getView(R.id.tv_origin_price); //添加下划线 originPriceView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); helper.setText(R.id.tv_origin_price, "¥" + originPrice); //商品图片 final AppCompatImageView imageView = helper.getView(R.id.iv); Glide.with(mContext) .applyDefaultRequestOptions(RECYCLE_OPTIONS) .load(goodsThumb) .into(imageView); //加入购物车图标 final ImageView shopCartImageView = helper.getView(R.id.iv_add_shopcart); shopCartImageView.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { //添加到购物车 Toast.makeText(Latte.getApplication(), goodsName + "已经加入购物车", Toast.LENGTH_SHORT).show(); final CircleImageView circleImageView = new CircleImageView(Latte.getApplication()); Glide.with(Latte.getApplication()) .applyDefaultRequestOptions(RECYCLE_OPTIONS) .load(goodsThumb) .into(circleImageView); final FrameLayout fromView = helper.getView(R.id.fl_section_shopcart); float[] minPosition = new float[2]; minPosition[0] = 0; minPosition[1] = -500; float[] targetPosition = new float[2]; targetPosition[0] = 0; targetPosition[1] = 2000; BazierAnimation.addToShopCart(circleImageView, fromView, minPosition, targetPosition); } }); break; default: break; } }
Example 17
Source File: ExploreListAdapter.java From C9MJ with Apache License 2.0 | 4 votes |
@Override protected void convert(final BaseViewHolder viewHolder, final ExploreListItemBean bean) { switch (viewHolder.getItemViewType()) { case ExploreListItemBean.ADS: List<View> viewList = new ArrayList<>(); ImageView iv_head = new ImageView(mContext); Glide.with(mContext) .load(bean.getImgsrc()) .crossFade() .centerCrop() .into(iv_head); viewList.add(iv_head); if (bean.getAds() != null) { for (ExploreListItemBean.AdsBean ads : bean.getAds()) { ImageView iv_ads = new ImageView(mContext); Glide.with(mContext) .load(ads.getImgsrc()) .crossFade() .centerCrop() .into(iv_ads); viewList.add(iv_ads); } } this.viewPager = viewHolder.getView(R.id.viewpager); this.viewHolder = viewHolder; this.bean = bean; final ExploreAdsAdapter pageAdapter = new ExploreAdsAdapter(viewList); viewPager.setOffscreenPageLimit(4); viewPager.setAdapter(pageAdapter); viewHolder.setText(R.id.tv_title, bean.getTitle()); viewPager.addOnPageChangeListener(pageChangeListener); //MagicIndicator MagicIndicator magicIndicator = viewHolder.getView(R.id.magic_indicator); magicIndicator.setVisibility(viewList.size() != 1 ? View.VISIBLE : View.GONE); ScaleCircleNavigator navigator = new ScaleCircleNavigator(mContext); navigator.setFollowTouch(true); navigator.setCircleCount(viewList.size()); magicIndicator.setNavigator(navigator); ViewPagerHelper.bind(magicIndicator, viewPager); viewHolder.addOnClickListener(R.id.viewpager); // viewPager.setCurrentItem(0); // pageChangeListener.onPageScrollStateChanged(ViewPager.SCROLL_STATE_IDLE); if (!isSubscribe) { flowable.subscribe(consumer); isSubscribe = true; } break; case ExploreListItemBean.NORMAL: viewHolder.setText(R.id.tv_title, bean.getTitle()) .setText(R.id.tv_source, bean.getSource()); Glide.with(mContext) .load(bean.getImgsrc()) .crossFade() .centerCrop() .into((ImageView) viewHolder.getView(R.id.iv_img)); break; default: break; } }