首页 > 解决方案 > running firebase query onClick and updating RecyclerView with results

问题描述

I'm trying to run a query on my firebase database in order to return only those results where timestamp = the date specified in the date picker (see picture of app) I want this query to run whenever I press the view records button

Application Selecting date

[![Firebase][3]][3]

I am able currently to print out all objects into the recycler view, however when attempting to run my query its not producing any results, no errors and no faults in debugging

If I need to provide anymore detail please let me know

[3]: https://i.stack.imgur.com/d2uu2.pngenter image description here

标签: javaandroidfirebaseandroid-recyclerview

解决方案


要解决此问题,请更改以下代码行:

options = new FirebaseRecyclerOptions.Builder<Records>().setQuery(databaseReference, Records.class).build();

options = new FirebaseRecyclerOptions.Builder<Records>().setQuery(query, Records.class).build();
//                                                                ^   ^

您必须将对象而不是对象传递给setQuery()方法,因为查询对象实际上过滤了您的数据。querydatabaseReference

编辑:

根据您的评论:

是的,它在硬编码时工作,但在将文本视图转换为字符串时它不起作用

这意味着传递查询对象可以解决问题,但问题仍然在于如何将数据转换为字符串。要解决这个问题,请确保 String 表示的date类型为:04-02-2017,您的问题将得到解决。


推荐阅读