我有一个这样的布局,在这里我可以得到订单数,并将其显示在我的recyclerview上。问题是我的清单上有2个项目,分别是1234和1235。正在显示1234中的所有数据,但由于有2个项目,它会循环两次。
以下是适配器的代码。
public class ReportDeliveredJobOrderAdapter extends RecyclerView.Adapter<ReportDeliveredJobOrderAdapter.ViewHolder> {
private Context context;
private List<JobOrderItem> objects = new ArrayList<>();
private LayoutInflater inflater;
private Callback.HistoryItemListener callback;
ReportDeliveredJobOrderAdapter(Context context) {
this.inflater = LayoutInflater.from(context);
this.context = context;
}
void updateHistoryAdapter(List<JobOrderItem> objects) {
this.objects = objects;
notifyDataSetChanged();
}
public void setCallback(Callback.HistoryItemListener callback) {
this.callback = callback;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View viewItem = inflater.inflate(R.layout.item_report_delivered_job_order, parent, false);
return new ViewHolder(viewItem);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final Object object = objects.get(position);
holder.bindJobOrder(object);
}
@Override
public int getItemCount() {
return objects.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.lblJobOrderID)
TextView lblJobOrderID;
@BindView(R.id.layoutDeliveredJO)
ConstraintLayout layoutDeliveredJO;
private JobOrderItem jobOrderItem;
final List<JobOrderItem> jobOrderItems = new ArrayList<>();
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
itemView.setOnClickListener(view -> {
int position = getLayoutPosition();
if (callback != null && position != RecyclerView.NO_POSITION) {
if (jobOrderItem.consignment_status != null) {
if (Preferences.getString(Prefkey.session_consignment_type).equals("runner-profiles") && jobOrderItem.consignment_status.equals("PrimaryRunner")) {
callback.onClickItem(jobOrderItem);
} else if (jobOrderItem.consignment_status.equals("withShopper")) {
Entity primary_shopper_profile = getPrimaryShopperEntity(jobOrderItem);
if (primary_shopper_profile != null) {
AppUtil.displayToast(context, context.getString(R.string.consignment_coordinate_shopper));
}
} else {
AppUtil.displayToast(context, context.getString(R.string.consignment_history_coordinate));
}
} else {
AppUtil.displayToast(context, context.getString(R.string.consignment_history_coordinate));
}
}
});
}
void bindJobOrder(Object object) {
this.jobOrderItem = (JobOrderItem) object;
for (Entity job_order : jobOrderItem.job_orders) {
lblJobOrderID.setText(String.format("JO# %s", job_order.id));
}
}
}
I am calling the jobOrderItems on DeliveredCheckoutAdapter. This is the code.
void bindCheckout(Object object){ this.jobOrderItem =(JobOrderItem)对象;
grand_total_amount = 0;
total_job_order_purchased_amount = 0;
total_job_order_delivery_fee = 0;
total_job_order_shopping_fee = 0;
total_job_order_discount = 0;
total_privilege_fee = 0;
total_credits = 0;
total_recalled = 0;
total_campaign_discount = 0;
jobOrderItems.clear();
final Date completed_at = parseServerDate(jobOrderItem.job_order.attributes.completed_at);
for (Entity job_order : jobOrderItem.job_orders) {
total_job_order_purchased_amount += job_order.attributes.purchased_deliverables_amount_in_cents;
total_job_order_delivery_fee += job_order.attributes.delivery_fee_in_cents;
total_privilege_fee += job_order.attributes.non_membership_fee_in_cents;
total_job_order_shopping_fee += job_order.attributes.shopping_fee_in_cents;
total_credits += job_order.attributes.credit_amount_of_cents;
total_recalled += job_order.attributes.recalled_deliverables_amount_in_cents;
}
for (JobOrderItem jobOrderItem : jobOrderItem.jobOrderItemList) {
if (!jobOrderItem.job_order.attributes.status.equals("cancelled")) {
if (jobOrderItem.job_order.relationships.completed_by_user.data.id.equals(Preferences.getString(Prefkey.session_user_id))) {
for (Entity campaigndiscount : jobOrderItem.campaigndiscounts) {
if (!jobOrderItem.job_order.attributes.status.equals("cancelled")) {
total_campaign_discount += campaigndiscount.attributes.discount_in_cents;
}
}
for (Entity discount : jobOrderItem.discounts) {
long job_order_discount;
if (discount.relationships.job_order.data.id.equals(jobOrderItem.job_order.id)) {
long purchase_amount = jobOrderItem.job_order.attributes.purchased_deliverables_amount_in_cents;
if (discount.attributes.sum_in_cents_off <= 0) {
job_order_discount = Math.round(purchase_amount * discount.attributes.percent_off);
} else {
job_order_discount = discount.attributes.sum_in_cents_off;
}
jobOrderItem.discount = purchase_amount;
total_job_order_discount += job_order_discount;
}
}
if (jobOrderItem.consignments.size() > 0) {
for (Entity consignment : jobOrderItem.consignments) {
Entity user = AppUtil.getEntity(consignment.relationships.user.data.id, jobOrderItem.users);
if (user.relationships.profile.data.type.equals("shopper-profiles")) {
if (consignment.attributes.primary) {
jobOrderItem.consignment_status = "withShopper";
}
} else if (user.relationships.profile.data.type.equals("runner-profiles")) {
if (consignment.attributes.primary) {
if (jobOrderItem.consignment_status == null || !jobOrderItem.consignment_status.equals("withShopper")) {
if (consignment.relationships.user.data.id.equals(Preferences.getString(Prefkey.session_user_id))) {
jobOrderItem.consignment_status = "PrimaryRunner";
}
}
}
}
}
}
} else {
if (jobOrderItem.consignments.size() > 0) {
for (Entity consignment : jobOrderItem.consignments) {
Entity user = AppUtil.getEntity(consignment.relationships.user.data.id, jobOrderItem.users);
if (user.relationships.profile.data.type.equals("shopper-profiles")) {
if (consignment.attributes.primary) {
jobOrderItem.consignment_status = "withShopper";
}
} else if (user.relationships.profile.data.type.equals("runner-profiles")) {
if (consignment.attributes.primary) {
if (jobOrderItem.consignment_status == null || !jobOrderItem.consignment_status.equals("withShopper")) {
if (consignment.relationships.user.data.id.equals(Preferences.getString(Prefkey.session_user_id))) {
jobOrderItem.consignment_status = "PrimaryRunner";
}
}
}
}
}
}
}
}
jobOrderItems.add(jobOrderItem);
}
reportDeliveredJobOrderAdapter.updateHistoryAdapter(jobOrderItems);
}