我使用第三方lib进度条,当我写 holder.donutprogress.setFinishedStrokeColor(colorsdark [progresspoint])时,一切正常但在 onBindViewHolder 方法
每个项目的颜色重复相同,当我看到日志颜色不同但只有第二个位置颜色在进度条中重复时
public class RatingAdapter extends RecyclerView.Adapter<RatingAdapter.ViewHolderRating> {
ArrayList<RatingResp> ratingModalList;
public Activity mActivity;
int colorsdark[]={R.color.progress_one_dark,R.color.progress_two_dark,R.color.progress_three_dark
,R.color.progress_four_dark};
int colorslight[]={R.color.progress_one_light,R.color.progress_two_light,R.color.progress_three_light
,R.color.progress_four_light};
int progresspoint=0;
class ViewHolderRating extends RecyclerView.ViewHolder {
@Nullable
@BindView(R.id.item_progress_rate)
DonutProgress donutprogress;
public ViewHolderRating(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
public RatingAdapter(Activity activity, ArrayList<RatingResp> items) {
this.ratingModalList = items;
this.mActivity = activity;
}
@Override
public ViewHolderRating onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_rating_raw, parent, false);
return new ViewHolderRating(view);
}
@Override
public void onBindViewHolder(ViewHolderRating holder, int position) {
configureViewHolderRating( holder, position);
}
private void configureViewHolderRating(RatingAdapter.ViewHolderRating holder, int position) {
if (progresspoint==4){
progresspoint=0;
}
Log.e("Progress color ",": "+colorsdark[progresspoint]);
RatingResp ratingResp = ratingModalList.get(position);
holder.donutprogress.setFinishedStrokeColor(colorsdark[progresspoint]);
holder.donutprogress.setUnfinishedStrokeColor(colorslight[progresspoint]);
holder.donutprogress.setInnerBottomTextColor(colorsdark[progresspoint]);
holder.donutprogress.setTextColor(colorsdark[progresspoint]);
progresspoint=progresspoint+1;
holder.donutprogress.setSuffixText(" ");
holder.donutprogress.setProgress(Integer.parseInt(ratingResp.getRating()));
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return ratingModalList.size();
}
}
这就是我将数据附加到我的回收视图的方式
LinearLayoutManager layoutManager
= new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
ratingAdapter = new RatingAdapter(getActivity(),ratingModalArrayList);
recrating.setLayoutManager(layoutManager);
recrating.setItemAnimator(new DefaultItemAnimator());
recrating.setAdapter(ratingAdapter);
答案 0 :(得分:0)
所以基本上我不知道它是如何工作的,但我刚刚添加了
int colorcodedark = ContextCompat.getColor(mActivity, colorsdark[progresspoint]);
int colorcodelight = ContextCompat.getColor(mActivity,colorslight[progresspoint]);
现在它的工作只需将configureViewHolderRating方法改为代码
private void configureViewHolderRating(RatingAdapter.ViewHolderRating holder, int position) {
RatingResp ratingResp = ratingModalList.get(position);
if (progresspoint==4){
progresspoint=0;
}else{
}
int colorcodedark = ContextCompat.getColor(mActivity, colorsdark[progresspoint]);
int colorcodelight = ContextCompat.getColor(mActivity,colorslight[progresspoint]);
holder.donutprogress.setFinishedStrokeColor(colorcodedark);
holder.donutprogress.setUnfinishedStrokeColor(colorcodelight);
holder.donutprogress.setInnerBottomTextColor(colorcodedark);
holder.donutprogress.setTextColor(colorcodedark);
progresspoint=progresspoint+1;
holder.donutprogress.setSuffixText(" ");
holder.donutprogress.setProgress(Integer.parseInt(ratingResp.getRating()));
}
如果任何人可以通过在方法中添加两个变量
来帮助我开始工作,那就太棒了