Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void showCartDialog() {
- if(boughtProduct == null || boughtProduct.size() == 0){
- Toast.makeText(context, "Produk belum dipilih.", Toast.LENGTH_SHORT).show();
- return;
- }
- final Dialog dialog = new Dialog(this);
- dialog.setContentView(R.layout.dialog_cartdetail);
- writeReceipt(dialog);
- dialog.findViewById(R.id.clearButton).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- LinearLayout cartLayout = dialog.findViewById(R.id.cartLinearLayout);
- cartLayout.removeAllViews();
- productIdList.clear();
- boughtProduct.clear();
- dialog.dismiss();
- }
- });
- dialog.findViewById(R.id.saveButton).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- for(int i = 0; i< productIdList.size(); i++){
- int tempId = productIdList.get(i);
- int tempBoughtAmount = boughtProduct.get(tempId);
- }
- boughtProduct.clear();
- productIdList.clear();
- productList.clear();
- productsAdapter.refreshGrid(productList);
- dialog.dismiss();
- }
- });
- dialog.show();
- }
- public void writeReceipt(Dialog dialog){
- LinearLayout cartLayout = dialog.findViewById(R.id.cartLinearLayout);
- int totalPrice = 0;
- cartLayout.removeAllViews();
- for(int i = 0; i < boughtProduct.size(); i++){
- LinearLayout linearLayout = new LinearLayout(this);
- linearLayout.setOrientation(LinearLayout.HORIZONTAL);
- linearLayout.setWeightSum(10);
- TextView productTextView = new TextView(this);
- productTextView.setText("Contoh Nama :");
- productTextView.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
- productTextView.setPadding(5,15,5,5);
- productTextView.setTextSize(15);
- productTextView.setTextColor(Color.BLACK);
- LinearLayout.LayoutParams productParams = new LinearLayout.LayoutParams(0,
- LinearLayout.LayoutParams.WRAP_CONTENT, 4);
- productParams.setMargins(30, 0, 0, 0);
- productTextView.setLayoutParams(productParams);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement