FirestoreRecyclerAdapter不更新视图 [英] FirestoreRecyclerAdapter not updating views

查看:61
本文介绍了FirestoreRecyclerAdapter不更新视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FirestoreRecyclerAdapter并遇到问题.

I`m using FirestoreRecyclerAdapter and faced with the problem.

                Query query = db
                .collection(SOME_COLLECTION)
                .whereEqualTo("key", key)                    
                .orderBy("dueDate");

如果我下单,则数据仅在第一次加载.实时更新不起作用.我尝试将orderBy放在最后,以及更改订购字段.

If I put orderBy, data loaded just first time. Real time updates not working. I tried putting orderBy at the end, as well as changing ordering fields.

如果我删除orderBy,则一切正常.但没有订购.

If I remove orderBy, all works well. But no ordering.

根据文档,当不使用范围比较时,它应该可以工作.有什么想法吗?

According to documentation it should work when not using range comparison. Any ideas?

已更新.这是适配器选项.

Updated. Here is adapter options.

             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);

所有设置都与示例相符,没什么花哨的.

All set accorting to examples, nothing fancy.

推荐答案

正如弗兰克所说,您应该创建索引.如果您更仔细地查看日志,则会有警告和创建索引的链接.只需单击链接即可.哥哥为您创建正确的索引.谢谢弗兰克.

As Frank said, you should create index. If you look more precise at log, there is a warning and a link to create index. Just click on link and that is it. Big brother creates right index for you. Thank you Frank.

这篇关于FirestoreRecyclerAdapter不更新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆