【问题标题】:Getting null values when passing data from activity to fragment using Parceable使用 Parcelable 将数据从活动传递到片段时获取空值
【发布时间】:2021-02-20 00:05:23
【问题描述】:

我正在尝试将 arraylist 从活动传递到片段,但我使用 parceable 得到一个空值。

在主要活动中:

Bundle bundle = new Bundle();
                    bundle.putParcelableArrayList("cbookings", customerbooking);
                    Todaybooking tb = new Todaybooking();
                    tb.setArguments(bundle);

数组列表数据声明

ArrayList<Cbooking> customerbooking = new ArrayList<>();

在片段中:

ArrayList<Cbooking> customerbooking = new ArrayList<>();

    Bundle extras = getActivity().getIntent().getExtras();
    customerbooking = extras.getParcelableArrayList("cbookings");
    Log.wtf("test", customerbooking.toString());

【问题讨论】:

    标签: android arrays android-bundle


    【解决方案1】:

    您正在使用setArguments() 将数据传递到片段中。因此,您需要使用getArguments() 来检索数据,而不是getActivity().getIntent().getExtras()

    【讨论】:

    • 即使我设置了 Bundle extras = getArguments();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多