android - 将 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();
解决方案
因此,您将拥有多种产品和至少 2 项活动(一项显示列表,一项显示其信息)。您应该创建一个 POJO 类的静态数组列表,其中包含详细信息变量,即(产品数量的名称、总数量和总价格),并且当用户添加一些产品时,您在此列表中创建一个条目。并在购物车中访问此数组列表以完成您的工作并将计算的总金额发送到我的销售活动。
推荐阅读
- python - 根据索引填写数据
- javascript - 如何将单个对象迭代到定义格式内的多个对象的新数组中
- python - 我使用 Kivy UrlReguest 下载并显示 Json 文件,但在 android 上没有任何效果,为什么?
- c# - 检测 C# 表单外的鼠标点击
- node.js - 如何在 NestJS 和 Jest 中测试 .map() 函数
- python - 在python中将大文件(500MB +)编码为base64
- tensorflow - 使用我的自定义损失函数时出现此错误:“张量”对象没有属性“_numpy”
- sql - Laravel Query Builder 加入别名
- tmap - tmap_save 中的错误:找不到对象“tm”
- plot - Seaborn 固定线图高度