[英]Sending sqlite data from one activity to another
我目前正在從事一個項目,需要幫助。
我想在我的添加到購物車活動中發送名稱,總數量和該產品數量的總價格。
在“添加到購物車”活動中,我想計算購物車中物品的總量,然后將其發送到我的銷售活動中,該活動將存儲購物車中發送的物品和每個物品的價格。
主要活動....
@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類創建一個靜態數組列表,該列表具有詳細信息變量(例如,產品的名稱,總數量和該產品數量的總價格),並且當用戶添加某些產品時,您將在此列表中進行輸入。 在購物車中訪問此數組列表以完成您的工作,並將計算出的總額發送給我的銷售活動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.