【发布时间】:2017-08-23 22:07:15
【问题描述】:
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
FirebaseRecyclerAdapter<Product, ProductViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Product, ProductViewHolder>(
Product.class,
R.layout.product_row,
ProductViewHolder.class,
mDatabase
) {
@Override
protected void populateViewHolder(ProductViewHolder viewHolder, Product model, int position) {
Log.d(TAG, "loading view " + position);
final String product_id = getRef(position).getKey();
viewHolder.setTitle(model.getName());
viewHolder.setDesc(model.getDesc());
viewHolder.setImage(getApplicationContext(), model.getImage());
viewHolder.setUsername(model.getUsername());
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent productDetailIntent = new Intent();
productDetailIntent.setClass(MainActivity.this, ProductDetailActivity.class);
productDetailIntent.putExtra("product_id", product_id);
Log.d(TAG + " product_id", product_id);
startActivity(productDetailIntent);
}
});
Log.d(TAG, "finish loading view");
}
};
mProductList.setAdapter(firebaseRecyclerAdapter);
}
以上是我用来从 firebase 实时数据库中获取数据的代码。如何更改查询(我的代码中的 mDatabase)并刷新 recyclerview 以过滤数据?如何设置新的适配器?请给我一些帮助。谢谢。
【问题讨论】:
-
您的意思是说您想在设置适配器后将新查询的结果加载到同一个 RecyclerView 中?
-
@DougStevenson 我有一个带有项目列表的 Firebase RV,当我在 RV 中使用“搜索”项目时,我需要过滤数据,有什么建议吗?
标签: android firebase firebase-realtime-database android-recyclerview android-adapter