gpt4 book ai didi

java - 如果在 RecyclerView onBindViewHolder 中有其他条件

转载 作者:行者123 更新时间:2023-11-30 05:09:05 27 4
gpt4 key购买 nike

我正在尝试在我的 onBindViewHolder() 上设置一个 if else 语句,以便它检查状态,然后根据找到的状态设置文本和文本颜色。

我已经尝试过了,但它只为我提供了 RecyclerView 中每个项目的第一个条件的结果。

这是我的适配器代码:

    public class PreviousSettingsAdapter extends RecyclerView.Adapter<PreviousSettingsAdapter.PreviousSettingsViewHolder> {
private List<Setting> SettingsModelList;
private Context context;

public PreviousSettingsAdapter(Context context, List<Setting> SettingsModelList) {
this.SettingsModelList = SettingsModelList;
this.context = context;
}

public class PreviousSettingsViewHolder extends RecyclerView.ViewHolder {

@BindView(R.id.date)
TextView date;
@BindView(R.id.Setting_id)
TextView SettingId;
@BindView(R.id.status)
TextView status;

public PreviousSettingsViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}

@NonNull
@Override
public PreviousSettingsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.placed_Setting_items, parent, false);
return new PreviousSettingsViewHolder(itemView);

}

@Override
public void onBindViewHolder(@NonNull PreviousSettingsViewHolder holder, int position) {
Setting singleSetting = SettingsModelList.get(position);
holder.date.setText(singleSetting.getCreatedAt());
holder.SettingId.setText("Setting Id: " + String.valueOf(singleSetting.getId()));


boolean paymentStatus = singleSetting.getConfirmed();
boolean fulfilledStatus = singleSetting.getProcessed();

if (paymentStatus && !fulfilledStatus ) {
holder.status.setText(R.string.processed);
holder.status.getResources().getColor(R.color.colorOrange);

} else
if (!paymentStatus && !fulfilledStatus) {
holder.status.setText(R.string.unchanged);
holder.status.getResources().getColor(R.color.colorRed);

} else if(paymentStatus && fulfilledStatus){
holder.status.setText(R.string.delivered);
holder.status.getResources().getColor(R.color.colorGreen);


}else{
holder.status.setText(" ");
}


}


@Override
public int getItemCount () {
return SettingsModelList.size();
}
}

最佳答案

调试并亲切地查看 paymentStatusfulfilledStatus 值。正如您所说,它可能会在满足这些条件的情况下进入 if 循环。

关于java - 如果在 RecyclerView onBindViewHolder 中有其他条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54017247/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com