Java Code Examples for com.chad.library.adapter.base.BaseViewHolder#getAdapterPosition()
The following examples show how to use
com.chad.library.adapter.base.BaseViewHolder#getAdapterPosition() .
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: FeedCategoryLeftAdapter.java From Focus with GNU General Public License v3.0 | 6 votes |
@Override protected void convert(BaseViewHolder helper, WebsiteCategory item) { if (currentPosition == helper.getAdapterPosition()){ helper.getView(R.id.iv_select).setVisibility(View.VISIBLE); if (SkinPreference.getInstance().getSkinName().equals("night")) { helper.setBackgroundColor(R.id.tv_item, UIUtil.getColor(R.color.white_night)); }else { helper.setBackgroundColor(R.id.tv_item, UIUtil.getColor(R.color.white)); } }else { if (SkinPreference.getInstance().getSkinName().equals("night")) { helper.setBackgroundColor(R.id.tv_item, UIUtil.getColor(R.color.colorPrimary_night)); }else { helper.setBackgroundColor(R.id.tv_item, UIUtil.getColor(R.color.colorPrimary)); } helper.getView(R.id.iv_select).setVisibility(View.GONE); } helper.setText(R.id.tv_item,item.getName()); }
Example 2
Source File: FeedCategoryLeftAdapter.java From Focus with GNU General Public License v3.0 | 6 votes |
@Override protected void convert(BaseViewHolder helper, WebsiteCategory item) { if (currentPosition == helper.getAdapterPosition()){ helper.getView(R.id.iv_select).setVisibility(View.VISIBLE); if (SkinPreference.getInstance().getSkinName().equals("night")) { helper.setBackgroundColor(R.id.tv_item, UIUtil.getColor(R.color.white_night)); }else { helper.setBackgroundColor(R.id.tv_item, UIUtil.getColor(R.color.white)); } }else { if (SkinPreference.getInstance().getSkinName().equals("night")) { helper.setBackgroundColor(R.id.tv_item, UIUtil.getColor(R.color.colorPrimary_night)); }else { helper.setBackgroundColor(R.id.tv_item, UIUtil.getColor(R.color.colorPrimary)); } helper.getView(R.id.iv_select).setVisibility(View.GONE); } helper.setText(R.id.tv_item,item.getName()); }
Example 3
Source File: CardWeatherAdapter.java From FakeWeather with Apache License 2.0 | 6 votes |
@Override protected void convert(final BaseViewHolder helper, WeatherCity item) { TextView tvName = helper.getView(R.id.tv_card_city_name); if (helper.getAdapterPosition() == 0) { tvName.setCompoundDrawablesWithIntrinsicBounds(null, null, ThemeUtil.setTintDrawable(R.drawable.ic_location, mContext, ThemeUtil.getCurrentColorPrimary(mContext)), null); } tvName.setText(item.getCityName()); helper.setText(R.id.tv_card_weather, TextUtils.isEmpty(item.getWeatherText()) ? "NA" : item.getWeatherText()); helper.setText(R.id.tv_card_temp, TextUtils.isEmpty(item.getWeatherTemp()) ? "NA" : item.getWeatherTemp() + "℃"); final ImageView imageView = helper.getView(R.id.iv_card_weather); WeatherUtil.getInstance().getWeatherDict(item.getWeatherCode()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SimpleSubscriber<WeatherBean>() { @Override public void onNext(WeatherBean weatherBean) { Glide.with(mContext).load(weatherBean.getIcon()).diskCacheStrategy(DiskCacheStrategy.ALL).into(imageView); } }); }
Example 4
Source File: WidgetAdapter.java From UIWidget with Apache License 2.0 | 6 votes |
@Override protected void convert(BaseViewHolder helper, WidgetEntity item) { int position = helper.getAdapterPosition() - getHeaderLayoutCount(); boolean status = position % 2 == 0; helper.setText(R.id.tv_titleWidget, item.title) .setText(R.id.tv_contentWidget, item.content); RadiusTextView radiusTextView = helper.getView(R.id.rtv_status_widget); radiusTextView.getDelegate() .setSelected(status); helper.itemView.setPadding(helper.itemView.getPaddingLeft(), helper.itemView.getPaddingTop() , helper.itemView.getPaddingBottom(), position == getData().size() - 1 ? NavigationBarUtil.getNavigationBarHeight((Activity) mContext) : 0); Log.i("position", "position:" + position); }
Example 5
Source File: WebAppAdapter.java From FastLib with Apache License 2.0 | 6 votes |
@Override protected void convert(BaseViewHolder helper, WebAppEntity item) { int index = helper.getAdapterPosition() % 3; int size = getData().size(); int percent = size % 3; RadiusTextView text = (RadiusTextView) helper.itemView; text.setText(item.title); text.getDelegate() .setTopDrawable(item.icon) .init(); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) helper.itemView.getLayoutParams(); if (params != null) { params.topMargin = mPadding; params.leftMargin = index == 0 ? mPadding : mPadding / 2; params.rightMargin = index == 2 ? mPadding : mPadding / 2; params.bottomMargin = helper.getAdapterPosition() == size - 1 || percent != 1 && helper.getAdapterPosition() == getData().size() - 2 || percent == 0 && helper.getAdapterPosition() == getData().size() - 3 ? mPadding : 0; } helper.itemView.setPadding(mPadding, mPaddingTop, mPadding, mPaddingTop); }
Example 6
Source File: UserFeedPostsVerticalAdapter.java From Focus with GNU General Public License v3.0 | 5 votes |
private void markReadOfTop(final BaseViewHolder helper, final FeedItem item){ for (int i = 0;i<helper.getAdapterPosition();i++){ feedItemList.get(i).setRead(true); feedItemList.get(i).save(); notifyItemChanged(i); } }
Example 7
Source File: UserFeedPostsVerticalAdapter.java From Focus with GNU General Public License v3.0 | 5 votes |
private void markReadOfBottom(final BaseViewHolder helper, final FeedItem item){ for (int i = helper.getAdapterPosition();i<feedItemList.size();i++){ feedItemList.get(i).setRead(true); feedItemList.get(i).save(); notifyItemChanged(i); } }
Example 8
Source File: ExampleBasicFragment.java From SmartRefreshHorizontal with Apache License 2.0 | 5 votes |
@Override protected void convert(BaseViewHolder holder, Void item) { int position = holder.getAdapterPosition(); holder.itemView.getLayoutParams().width = -2;//DensityUtil.dp2px(100); holder.itemView.getLayoutParams().height = -1; holder.itemView.setBackgroundResource(colorIds[position%colorIds.length]); holder.setText(android.R.id.text1, getString(R.string.item_example_number_title, position)); holder.setTextColor(android.R.id.text1, 0xffffffff); }
Example 9
Source File: UserFeedPostsVerticalAdapter.java From Focus with GNU General Public License v3.0 | 5 votes |
private void markReadOfTop(final BaseViewHolder helper, final FeedItem item){ for (int i = 0;i<helper.getAdapterPosition();i++){ feedItemList.get(i).setRead(true); feedItemList.get(i).save(); notifyItemChanged(i); } }
Example 10
Source File: UserFeedPostsVerticalAdapter.java From Focus with GNU General Public License v3.0 | 5 votes |
private void markReadOfBottom(final BaseViewHolder helper, final FeedItem item){ for (int i = helper.getAdapterPosition();i<feedItemList.size();i++){ feedItemList.get(i).setRead(true); feedItemList.get(i).save(); notifyItemChanged(i); } }
Example 11
Source File: SimpleListAdapter.java From FakeWeather with Apache License 2.0 | 5 votes |
@Override protected void convert(BaseViewHolder helper, SimpleItem item) { helper.setText(R.id.tv_simple, item.getItem()); if (helper.getAdapterPosition() == lastSelectedIndex) { helper.itemView.setSelected(true); } else { helper.itemView.setSelected(false); } }
Example 12
Source File: TitleAdapter.java From UIWidget with Apache License 2.0 | 5 votes |
@Override protected void convert(BaseViewHolder helper, TitleEntity item) { int position = helper.getAdapterPosition() - getHeaderLayoutCount(); helper.setText(R.id.tv_titleWidget, item.title); helper.setText(R.id.tv_contentWidget, item.content); helper.itemView.setPadding(helper.itemView.getPaddingLeft(),helper.itemView.getPaddingTop() ,helper.itemView.getPaddingBottom(),position == getData().size()-1? NavigationBarUtil.getNavigationBarHeight((Activity)mContext):0); }
Example 13
Source File: MainRecyclerAdapter.java From HaiNaBaiChuan with Apache License 2.0 | 5 votes |
@Override protected void convert(BaseViewHolder baseViewHolder, MainTag mainTag) { TextView textView = baseViewHolder.getView(R.id.tagContent); textView.setText(mainTag.getName()); ViewGroup.LayoutParams params = textView.getLayoutParams(); int position = baseViewHolder.getAdapterPosition(); if (widthList.size() <= position || widthList.get(position) == null) { widthList.add(params.width); } else { params.width = widthList.get(position); textView.setLayoutParams(params); } }
Example 14
Source File: EditUserInfoAdapter.java From HaiNaBaiChuan with Apache License 2.0 | 5 votes |
@Override protected void convert(BaseViewHolder baseViewHolder, EditItem editItem) { ImageView imgHead = baseViewHolder.getView(R.id.imgHead); TextView tvTypeName = baseViewHolder.getView(R.id.tvTypeName); tvTypeName.getPaint().setFakeBoldText(true); baseViewHolder.setText(R.id.tvTypeName, editItem.getTypeName()) .setText(R.id.tvValue, editItem.getValue()); if (baseViewHolder.getAdapterPosition() == 0) { imgHead.setVisibility(View.VISIBLE); ImgLoadUtil.loadHead(mContext, imgHead, editItem.getHeadPic()); } else { imgHead.setVisibility(View.GONE); } }
Example 15
Source File: FriendsAdapter.java From Android-IM with Apache License 2.0 | 4 votes |
@Override protected void convert(BaseViewHolder helper, final T item) { final Button button = helper.getView(R.id.item_main_bt); final TextView time = helper.getView(R.id.item_main_time); final ImageView imageView = helper.getView(R.id.item_main_img); if (mMessageType != null) { switch (mMessageType) { case RECOMMEND: //推荐列表 // if (item.getFriends()) { // button.setText("已添加"); // button.setEnabled(false); // } else { // button.setText("添加"); // button.setEnabled(true); // } // button.setVisibility(View.VISIBLE); // button.setOnClickListener( // new View.OnClickListener() { // @Override // public void onClick(View view) { // Intent intent = new Intent(mContext, AddFriendMsgActivity.class); // intent.putExtra("ID", item.getContent()); // intent.putExtra("NAME", item.getTitle()); // mContext.startActivity(intent); // } // }); break; case FRIENDS: //好友列表 UserInfo data = (UserInfo) item; if (helper.getAdapterPosition() == 0) { LogUtils.e("nakeName:"+data.getNickname()+",userName:"+data.getUserName()+",id:"+data.getUserID()); } String name = ""; if (!data.getNickname().isEmpty()) { name = data.getNickname(); }else if (!data.getUserName().isEmpty()){ name = data.getUserName(); }else { name =""+data.getUserID(); } helper.setText(R.id.item_main_username, name) .setText(R.id.item_main_content, data.getSignature()) .setText(R.id.item_main_time, TimeUtils.unix2Date("MM-dd HH:mm", data.getmTime())); GlideUtil.loadUserHeadImg(mContext,data.getAvatar(),imageView); break; case CERT: // JMessageClient.getUserInfo(item.getUserName(), new GetUserInfoCallback() { // @Override // public void gotResult(int i, String s, UserInfo userInfo) { // if (i == 0) { // Log.e("isFriends", userInfo.getUserName() + "...." + userInfo.isFriend()); // if (userInfo.isFriend()) { // button.setText("已同意"); // button.setEnabled(false); // } else { // button.setText("同意"); // button.setEnabled(true); // } // button.setVisibility(View.VISIBLE); // } // } // }); // button.setOnClickListener( // new View.OnClickListener() { // @Override // public void onClick(View view) { // ContactManager.acceptInvitation(item.getUserName(), "", new BasicCallback() { // @Override // public void gotResult(int i, String s) { // if (i == 0) { // button.setText("已同意"); // } else { // ToastUtils.showShort("验证失败"); // } // } // }); // } // }); break; case MESSAGE: //会话列表 // if (Integer.valueOf(item.time) <= 0) { // time.setText(item.time + "条未读消息"); // time.setTextColor(Color.parseColor("#66000000")); // } else { // time.setText(item.time + "条未读消息"); // time.setTextColor(Color.parseColor("#E5955D")); // } break; default: break; } } }