Reputation: 153
I am currently working on a project and I need assistance.
I want to send the name, total quantities and total price of that quantity of a product in my to my add to cart activity.
In the add to cart activity, I want to calculate the total amount of the items in the cart and then send to my sales activity which will store the items and the prices for every item sent from the cart.
MainActivity....
@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) {
What code should be above to send to cart activity??
Toast.makeText(MainActivity.this, "Added To Cart", 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();
Upvotes: 2
Views: 89
Reputation: 578
So you will have multiple products and atleast 2 activities (one showing the list and one its info) . You should create a static array list of a POJO class having variables of details ie( name, total quantities and total price of that quantity of a product) and when a user add some product you make a entry in this list . And in cart access this arraylist to do your work and send the calculated total amount to my sales activity .
Upvotes: 1