我正在使用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);
所有设置都符合示例,没什么特别的。
答案 0 :(得分:1)
正如弗兰克所说,你应该创建索引。如果您在日志中看起来更精确,则会出现警告和创建索引的链接。只需点击链接就可以了。大哥为你创造了正确的索引。谢谢Frank。