【发布时间】:2017-12-01 02:03:39
【问题描述】:
我正在使用 FirestoreRecyclerAdapter 并遇到了问题。
Query query = db
.collection(SOME_COLLECTION)
.whereEqualTo("key", key)
.orderBy("dueDate");
如果我输入 orderBy,数据只是第一次加载。实时更新不起作用。我尝试将 orderBy 放在最后,以及更改排序字段。
如果我删除 orderBy,一切正常。但没有订购。
根据文档,它在不使用范围比较时应该可以工作。有什么想法吗?
已更新。这是适配器选项。
FirestoreRecyclerOptions<Payment> options =
new FirestoreRecyclerOptions.Builder<Payment>()
.setQuery(query, Payment.class)
.build();
这里是付款。
public class Payment {
private String key;
private double amount;
private Date cDate;
private Date paidDate;
private Date dueDate;
private boolean isPaid;
public Payment() {
}
Payment(String key, double amount, Date cDate, Date paidDate, Date dueDate, boolean isPaid) {
this.key = key;
this.amount = amount;
this.cDate = cDate;
this.paidDate = paidDate;
this.dueDate = dueDate;
this.isPaid = isPaid;
}
}
这里是付款持有人。
class PaymentHolder extends RecyclerView.ViewHolder {
private TextView pDate, pAmount;
private CheckBox pDone;
PaymentHolder(View itemView) {
super(itemView);
pDate = itemView.findViewById(R.id.pDate);
pAmount = itemView.findViewById(R.id.pAmount);
pDone = itemView.findViewById(R.id.checkBox);
}}
这是适配器。
firestoreRecyclerAdapter = new FirestoreRecyclerAdapter<Payment, PaymentHolder>(options) {
@Override
protected void onBindViewHolder(final PaymentHolder paymentHolder, final int position, final Payment payment) {
final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
final String id = getSnapshots().getSnapshot(position).getId();
paymentHolder.getpDate().setText(dateFormat.format(payment.getDueDate()));
paymentHolder.getpAmount().setText(getAmount(payment.getAmount()));
paymentHolder.getpDone().setChecked(payment.isPaid());
}
@Override
public PaymentHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.payment_item, viewGroup, false);
final PaymentHolder paymentHolder = new PaymentHolder(view);
return paymentHolder;
}
};
recyclerView.setAdapter(firestoreRecyclerAdapter);
所有设置都根据示例,没有什么花哨的。
【问题讨论】:
-
您共享的代码对
FirestoreRecyclerAdapter没有任何作用。没有看到minimal complete code that reproduces the problem,很难说出了什么问题(阅读链接,它非常有用)。 -
您是否在该字段组合上定义了索引?如果没有,您应该在 logcat 中收到关于 out 的非常明确的警告。
标签: android google-cloud-firestore