我正在制作一个计费应用程序,从firestore加载产品数据。我已将属性设置为“活动-非活动”产品。但当我加载所有产品并隐藏非活动产品时,它显示的是空白。
加载gridlayoutmanager的代码:
GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(), 2);
recyclerView.setLayoutManager(gridLayoutManager); // set LayoutManager to RecyclerView
recyclerView.setHasFixedSize(false);
具有以下条件的适配器:
@Override
public void onBindViewHolder(@NonNull final PosProductAdapter.MyViewHolder holder, int position) {
String pcode = productData.get(position).getProduct_code();
String productId = productData.get(position).getProductId();
firebaseFirestore.collection("products")
.document(pcode)
.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists())
{
String s = documentSnapshot.getString("pStatus");
Toast.makeText(context, s, Toast.LENGTH_SHORT).show();
if (s.equals("inactive"))
{
holder.pos_product_ll.setVisibility(View.GONE);
holder.btnAddToCart.setVisibility(View.GONE);
}
}
}
});
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="?android:attr/selectableItemBackground"
android:layout_width="match_parent"
android:id="@+id/pos_product_ll"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="@+id/card_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:foreground="?android:attr/selectableItemBackground"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:cardCornerRadius="10dp"
app:cardElevation="0dp">
</androidx.cardview.widget.CardView>
</LinearLayout>
1条答案
按热度按时间rsaldnfx1#
使用适配器和firebase时,必须正确处理它们。