Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. public void showCartDialog() {
  2. if(boughtProduct == null || boughtProduct.size() == 0){
  3. Toast.makeText(context, "Produk belum dipilih.", Toast.LENGTH_SHORT).show();
  4. return;
  5. }
  6.  
  7. final Dialog dialog = new Dialog(this);
  8. dialog.setContentView(R.layout.dialog_cartdetail);
  9.  
  10. writeReceipt(dialog);
  11.  
  12. dialog.findViewById(R.id.clearButton).setOnClickListener(new View.OnClickListener() {
  13. @Override
  14. public void onClick(View view) {
  15. LinearLayout cartLayout = dialog.findViewById(R.id.cartLinearLayout);
  16. cartLayout.removeAllViews();
  17.  
  18. productIdList.clear();
  19. boughtProduct.clear();
  20.  
  21. dialog.dismiss();
  22. }
  23. });
  24.  
  25. dialog.findViewById(R.id.saveButton).setOnClickListener(new View.OnClickListener() {
  26. @Override
  27. public void onClick(View view) {
  28. for(int i = 0; i< productIdList.size(); i++){
  29. int tempId = productIdList.get(i);
  30. int tempBoughtAmount = boughtProduct.get(tempId);
  31. }
  32.  
  33. boughtProduct.clear();
  34. productIdList.clear();
  35. productList.clear();
  36.  
  37. productsAdapter.refreshGrid(productList);
  38.  
  39. dialog.dismiss();
  40. }
  41. });
  42.  
  43. dialog.show();
  44. }
  45.  
  46. public void writeReceipt(Dialog dialog){
  47. LinearLayout cartLayout = dialog.findViewById(R.id.cartLinearLayout);
  48. int totalPrice = 0;
  49.  
  50. cartLayout.removeAllViews();
  51.  
  52. for(int i = 0; i < boughtProduct.size(); i++){
  53. LinearLayout linearLayout = new LinearLayout(this);
  54. linearLayout.setOrientation(LinearLayout.HORIZONTAL);
  55. linearLayout.setWeightSum(10);
  56.  
  57. TextView productTextView = new TextView(this);
  58. productTextView.setText("Contoh Nama :");
  59. productTextView.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
  60. productTextView.setPadding(5,15,5,5);
  61. productTextView.setTextSize(15);
  62. productTextView.setTextColor(Color.BLACK);
  63. LinearLayout.LayoutParams productParams = new LinearLayout.LayoutParams(0,
  64. LinearLayout.LayoutParams.WRAP_CONTENT, 4);
  65. productParams.setMargins(30, 0, 0, 0);
  66. productTextView.setLayoutParams(productParams);
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement