TextView 没有出现。空白卡片浏览量

TextView not appearing. Blank CardViews

我目前正在做一个基本的购物车项目,我从 RecyclerView select 项目并将它们添加到自定义 ArrayList,然后应该在新的 Recycleview 的 EstimateActivity 中看到.我能够将自定义对象添加到“cartList”并通过意图(通过可解析)传递它。当我单击按钮转到估计 Activity 时,新 RecyclerView 中出现的所有内容都是适量的 CardView,没有任何 TextView(代码和名称)。由于在 EstimateActivity 的 RecyclerView 中找到了正确数量的 CardView,我是否认为意图被正确传递是错误的?由于其他一切正常,我很难找出错误所在。任何有关如何自行解决此类错误的帮助也将不胜感激。

以下是我将意图从 Main Activity 传递到 Estimate Activity 的方式:


         button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                    Intent intent = new Intent(MainActivity.this, EstimateActivity.class);
                    intent.putExtra("cartList", cartList); 
                    v.getContext().startActivity(intent);
            }
        });

这是估计值Activity:


        
public class EstimateActivity extends AppCompatActivity {
    private RecyclerView eRecyclerview;
    private CartAdapter eAdapter;
    private RecyclerView.LayoutManager eLayoutManager;
    private ArrayList<Inventory> eCartList;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_estimate);

        eCartList = new ArrayList<Inventory>();
        Bundle bundle = getIntent().getExtras();
        eCartList = bundle.getParcelableArrayList("cartList");

        eRecyclerview = findViewById(R.id.recyclerview);
        eLayoutManager = new LinearLayoutManager(this);
        eAdapter = new CartAdapter(eCartList); //  THIS IS WHERE IM PASSING THE LIST
        eRecyclerview.setLayoutManager(eLayoutManager);
        eRecyclerview.setAdapter(eAdapter);

    }
}

这是 CartAdapter:


        
public class CartAdapter extends RecyclerView.Adapter<CartAdapter.CartViewHolder> {
    private ArrayList<Inventory> eInventoryList;

    public static class CartViewHolder extends RecyclerView.ViewHolder {
        private TextView eCardCode;
        private TextView eCardName;
        private CardView eContainerView;

        public CartViewHolder(View itemView) {
            super(itemView);
            eCardCode = itemView.findViewById(R.id.code_view);
            eCardName = itemView.findViewById(R.id.name_view);
            eContainerView = itemView.findViewById(R.id.container_view2);
        }
    }

    public CartAdapter(ArrayList<Inventory> eCartList){   //this is where i recieve the list
       eInventoryList = eCartList;
    }

    @NonNull
    @Override
    public CartViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.text_row, parent, false);
        CartViewHolder mvh = new CartViewHolder(view);
        return mvh;
    }

    @Override
    public void onBindViewHolder(@NonNull CartViewHolder holder, int position) {
        Inventory currentItem = eInventoryList.get(position);
        holder.eCardName.setText(currentItem.getName());
        holder.eCardCode.setText(currentItem.getCode());
        holder.eContainerView.setTag(currentItem);
    }



    @Override
    public int getItemCount() {
        return eInventoryList.size();
    }
}                

最后是 RecyclerView 中 CardView 的 XML


        <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="@color/black"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="5dp"
    android:padding="5dp"
    android:layout_marginBottom="2dp"
    android:layout_marginTop="2dp"
    android:id="@+id/container_view2"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="4dp">
        <TextView
            android:id="@+id/code_view"
            android:text="code_view"
            android:textSize="10sp"
            android:textColor="@color/white"
            android:layout_centerInParent="true"
            android:layout_alignParentTop="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            />

        <TextView
            android:id="@+id/name_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:layout_alignParentTop="true"
            android:layout_marginTop="0dp"
            android:text="Name Name Name Name Name"
            android:textColor="@android:color/white"
            android:textSize="20sp"
            android:textStyle="bold"
            android:paddingTop="10dp"
            />


    </RelativeLayout>

</androidx.cardview.widget.CardView>

尝试调试应用程序,在收到包内容后放置一个断点并检查它有哪些值以确保它顺利到达,你可以在适配器内部做同样的事情。 每次需要知道变量在特定时间和地点有什么值时都可以这样做 祝你在这个新世界好运!!