首页 > 解决方案 > 将 sqlite 数据从一个活动发送到另一个活动

问题描述

我目前正在做一个项目,我需要帮助。

我想将我的产品的名称、总数量和总价格发送到我的添加到购物车活动中。

在添加到购物车活动中,我想计算购物车中商品的总量,然后发送到我的销售活动,该活动将存储商品以及从购物车发送的每件商品的价格。

主要活动....

@Override public void onListClick(final ItemInfo item) {

    numberPicker = new MaterialNumberPicker.Builder(self)
            .minValue(1)
            .maxValue(100)
            .defaultValue(1)
            .backgroundColor(Color.TRANSPARENT)
            .separatorColor(Color.TRANSPARENT)
            .textColor(Color.BLACK)
            .textSize(20)
            .enableFocusability(false)
            .wrapSelectorWheel(true)
            .build();

    new MaterialDialog.Builder(self)
            .title(item.getItemName())
            .customView(numberPicker, true)
            .positiveColor(getResources().getColor(R.color.colorTurquoise))
            .negativeColor(getResources().getColor(R.color.colorPrimaryDark))
            .positiveText("Ok")
            .negativeText("Cancel")
            .cancelable(false)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    MaterialDialog mMaterialDialog = new MaterialDialog.Builder(self)
                            .title("Total")
                            .customView(R.layout.layout_popup_sales, true)
                            .autoDismiss(false)
                            .positiveColor(getResources().getColor(R.color.colorTurquoise))
                            .negativeColor(getResources().getColor(R.color.colorPrimaryDark))
                            .positiveText("Add to Cart")
                            .negativeText("Cancel")
                            .cancelable(false)
                            .onPositive(new MaterialDialog.SingleButtonCallback() {
                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

上面应该有什么代码发送到购物车活动?

Toast.makeText(MainActivity.this, "添加到购物车", Toast.LENGTH_SHORT).show();

                            .onNegative(new MaterialDialog.SingleButtonCallback() {
                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    dialog.dismiss();
                                }
                            })
                            .build();


                    TextView mPopupName = (TextView) mMaterialDialog.getCustomView().findViewById(R.id.layout_popup_sales_name);
                    mPopupName.setText(item.getItemName());
                    TextView mPopupQuantity = (TextView) mMaterialDialog.getCustomView().findViewById(R.id.layout_popup_sales_quantity);
                    mPopupQuantity.setText("(" + numberPicker.getValue() + Constant.UNITS + " - " + Constant.NGN + item.getItemPrice() + ")");
                    TextView mPopupPrice = (TextView) mMaterialDialog.getCustomView().findViewById(R.id.layout_popup_sales_price);
                    mPopupPrice.setText(Constant.NGN + (numberPicker.getValue() * item.getItemPrice()));
                    mMaterialDialog.show();
                }
            })
            .onNegative(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    dialog.dismiss();
                }
            })
            .show();

标签: androidandroid-studio

解决方案


因此,您将拥有多种产品和至少 2 项活动(一项显示列表,一项显示其信息)。您应该创建一个 POJO 类的静态数组列表,其中包含详细信息变量,即(产品数量的名称、总数量和总价格),并且当用户添加一些产品时,您在此列表中创建一个条目。并在购物车中访问此数组列表以完成您的工作并将计算的总金额发送到我的销售活动。


推荐阅读