我正在编写一个应用程序来测试firebase,用户可以在其中列出带有图像的产品.我有上传的问题,因为虽然图片存储,但它们没有链接到产品(图像数组没有被传递?)和LeakCanary发出了一个内存错误信号.所有帮助和输入赞赏.
这是我的产品型号
@IgnoreExtraProperties
public class Product {
public String uid;
public String seller;
public String name;
public String description;
public String city;
public double price = 0.0;
public List<Uri> images = new ArrayList<>();
public Product () {
}
public Product(String uid, String seller, String name, String description, String city, double price, List<Uri> images) {
this.uid = uid;
this.seller = seller;
this.name = name;
this.description = description;
this.city = city;
this.price = price;
this.images = images;
}
// [START post_to_map]
@Exclude …Run Code Online (Sandbox Code Playgroud) android firebase firebase-realtime-database firebase-storage
我目前正在使用Firebase编写Android应用程序.我有一个具有城市属性的产品型号.我正在运行以下查询:
mDatabaseReference = FirebaseDatabase.getInstance().getReference();
mDatabaseReference.keepSynced(true);
productQuery = mDatabaseReference.child("products")
.orderByChild("city").equalTo(mCurrentUser).limitToFirst(100);
Run Code Online (Sandbox Code Playgroud)
无论城市如何,此查询都会检索数据库中的所有产品.
我花了最后四个小时审查关于SO的类似问题,并尝试查询函数的不同组合+规则索引无济于事.我有一个我称之为愚蠢的解决方案,它重新复制城市产品树下的数据.但是我猜测有一个更好的方法来利用orderByChild,如果我能得到一些帮助来查询城市数据,我将不胜感激.
感谢您的输入
这是CityFeed片段 - 注意:我检查了mCurrentUserCity已设置
public class CityFeedFragment extends BaseFragment {
private RecyclerView mRecyclerView;
private String mCurrentUserCity;
private FirebaseProductAdapter mAdapter;
private DatabaseReference mDatabaseReference;
private LinearLayoutManager mManager;
private Query productQuery;
private SwipeRefreshLayout mSwipeRefreshLayout;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_feed, container, false);
mDatabaseReference = FirebaseDatabase.getInstance().getReference();
mDatabaseReference.keepSynced(true);
retrieveCity();
fetchProducts();
mAdapter = new FirebaseProductAdapter(Product.class, …Run Code Online (Sandbox Code Playgroud)