Bonjour
Depuis 3 jours je galere pour faire afficher mon resultat double si je le passe en int cela fonctionne parfaitement sauf que je n ai pas les chiffres apres la virgule et lorque je passe en double le resultat est a 0 je passe par un adapter , model et l activity désolé je vais mettre tous le code car l erreur doit etre bete ou non d ailleurs
Pour information j ai mis un toast sur le calcul de l adaptateur et celui ci envoie bien le resultat mais lorsque je recupere le intent dans un toast je vois bien qu il me recupere les données mais d un seul coup il me met 0 au lieu
MyCartModel
MyCartAdapter
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 public class MyCartModel { String currentTime; String currentDate; String productName; String productSize; String productPrice; String totalQuantity; String productRating; double totalPrice; String gantGauche1; String gantGauche2; String gantGaucheDrapeau; String gantDroit1; String gantDroit2; String gantDroitDrapeau; String documentId; public MyCartModel() { } public String getDocumentId() { return documentId; } public void setDocumentId(String documentId) { this.documentId = documentId; } public MyCartModel(String currentTime, String currentDate, String productName, String productPrice, String productRating, String totalQuantity, String productSize, double totalPrice, String gantGauche1, String gantGauche2, String gantGaucheDrapeau, String gantDroit1, String gantDroit2, String gantDroitDrapeau) { this.currentTime = currentTime; this.currentDate = currentDate; this.productName = productName; this.productPrice = productPrice; this.totalQuantity = totalQuantity; this.totalPrice = totalPrice; this.productSize=productSize; this.productRating=productRating; this.gantGauche1=gantGauche1; this.gantGauche2=gantGauche2; this.gantGaucheDrapeau=gantGaucheDrapeau; this.gantDroit1=gantDroit1; this.gantDroit2=gantDroit2; this.gantDroitDrapeau=gantDroitDrapeau; } public String getCurrentTime() { return currentTime; } public void setCurrentTime(String currentTime) { this.currentTime = currentTime; } public String getProductRating() { return productRating; } public void setProductRating(String productRating) { this.productRating = productRating; } public String getCurrentDate() { return currentDate; } public void setCurrentDate(String currentDate) { this.currentDate = currentDate; } public String getProductSize() { return productSize; } public void setProductSize(String productSize) { this.productSize = productSize; } public String getProductName() { return productName; } public void setProductName(String productName) { this.productName = productName; } public String getGantGauche1() { return gantGauche1; } public void setGantGauche1(String gantGauche1) { this.gantGauche1 = gantGauche1; } public String getGantGauche2() { return gantGauche2; } public void setGantGauche2(String gantGauche2) { this.gantGauche2 = gantGauche2; } public String getGantGaucheDrapeau() { return gantGaucheDrapeau; } public void setGantGaucheDrapeau(String gantGaucheDrapeau) { this.gantGaucheDrapeau = gantGaucheDrapeau; } public String getGantDroit1() { return gantDroit1; } public void setGantDroit1(String gantDroit1) { this.gantDroit1 = gantDroit1; } public String getGantDroit2() { return gantDroit2; } public void setGantDroit2(String gantDroit2) { this.gantDroit2 = gantDroit2; } public String getGantDroitDrapeau() { return gantDroitDrapeau; } public void setGantDroitDrapeau(String gantDroitDrapeau) { this.gantDroitDrapeau = gantDroitDrapeau; } public String getProductPrice() { return productPrice; } public void setProductPrice(String productPrice) { this.productPrice = productPrice; } public String getTotalQuantity() { return totalQuantity; } public void setTotalQuantity(String totalQuantity) { this.totalQuantity = totalQuantity; } public double getTotalPrice() { return totalPrice; } public void setTotalPrice(double totalPrice) { this.totalPrice = totalPrice; } }
MyCartAcitity
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 public class MyCartAdapter extends RecyclerView.Adapter<MyCartAdapter.ViewHolder> { Context context; List<MyCartModel> list; double totalAmount=0.00 ; FirebaseFirestore firestore; FirebaseAuth auth; double overTotalPrice=0; public MyCartAdapter(Context context,List<MyCartModel>list){ this.context=context; this.list=list; firestore=FirebaseFirestore.getInstance(); auth = FirebaseAuth.getInstance(); } @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.my_cart_items,parent,false)); } @Override public void onBindViewHolder(@NonNull ViewHolder holder, final int position) { holder.date.setText(list.get(position).getCurrentDate()); holder.time.setText(list.get(position).getCurrentTime()); holder.price.setText(list.get(position).getProductPrice()+""); holder.size.setText(list.get(position).getProductSize()); holder.rating.setText(list.get(position).getProductRating()); holder.name.setText(list.get(position).getProductName()); holder.totalPrice.setText(String.valueOf(list.get(position).getTotalPrice())); holder.totalQuantity.setText(list.get(position).getTotalQuantity()); holder.gantGauche1.setText(list.get(position).getGantGauche1()); holder.gantGauche2.setText(list.get(position).getGantGauche2()); holder.gantGaucheDrapeau.setText(list.get(position).getGantGaucheDrapeau()); holder.gantDroit1.setText(list.get(position).getGantDroit1()); holder.gantDroit2.setText(list.get(position).getGantDroit2()); holder.gantDroitDrapeau.setText(list.get(position).getGantDroitDrapeau()); holder.suppBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { firestore.collection("AddToCart").document(auth.getCurrentUser().getUid()) .collection("User") .document(list.get(position).getDocumentId()) .delete() .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()){ list.remove(list.get(position)); notifyDataSetChanged(); Toast.makeText(context, "Supprimer", Toast.LENGTH_SHORT).show(); ((Activity)context).recreate(); }else{ Toast.makeText(context,"Echec"+task.getException().getMessage(),Toast.LENGTH_SHORT).show(); } } }); } }); String a,b,c,d,e,f; a=holder.gantGauche1.getText().toString(); b=holder.gantGauche2.getText().toString(); c=holder.gantGaucheDrapeau.getText().toString(); d=holder.gantDroit1.getText().toString(); e=holder.gantDroit2.getText().toString(); f=holder.gantDroitDrapeau.getText().toString(); if (a.equals("") && f.equals("") && b.equals("") && c.equals("") && d.equals("") && e.equals("")){ holder.gantGauche1.setVisibility(View.GONE); holder.gantGauche2.setVisibility(View.GONE); holder.gantGaucheDrapeau.setVisibility(View.GONE); holder.gantDroit1.setVisibility(View.GONE); holder.gantDroit2.setVisibility(View.GONE); holder.gantDroitDrapeau.setVisibility(View.GONE); holder.gant1.setVisibility(View.GONE); holder.gant2.setVisibility(View.GONE); holder.gant3.setVisibility(View.GONE); holder.gant4.setVisibility(View.GONE); holder.gant5.setVisibility(View.GONE); holder.gant6.setVisibility(View.GONE); } //total amount pass to cart activity totalAmount = (totalAmount + list.get(position).getTotalPrice()); Intent intent = new Intent("MyTotalAmount"); intent.putExtra("totalAmount",totalAmount); Toast.makeText(context, totalAmount+"", Toast.LENGTH_SHORT).show(); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } @Override public int getItemCount() { return list.size(); } public class ViewHolder extends RecyclerView.ViewHolder{ TextView name,price,date,time,totalQuantity,totalPrice,size,rating,gantGauche1,gantGauche2,gantGaucheDrapeau,gantDroit1,gantDroit2,gantDroitDrapeau,gant1,gant2,gant3,gant4,gant5,gant6; Button suppBtn,NextProcessBtn; public ViewHolder(@NonNull View itemView) { super(itemView); name=itemView.findViewById(R.id.product_name); price=itemView.findViewById(R.id.product_price); date=itemView.findViewById(R.id.current_date); time=itemView.findViewById(R.id.current_time); rating=itemView.findViewById(R.id.reference); totalQuantity=itemView.findViewById(R.id.total_quantity); totalPrice=itemView.findViewById(R.id.total_price); size=itemView.findViewById(R.id.size); gantGauche1=itemView.findViewById(R.id.gg1text); gantGauche2=itemView.findViewById(R.id.gg2text); gantGaucheDrapeau=itemView.findViewById(R.id.ggdtext); gantDroit1=itemView.findViewById(R.id.gd1text); gantDroit2=itemView.findViewById(R.id.gd2text); gantDroitDrapeau=itemView.findViewById(R.id.gddtext); gant1=itemView.findViewById(R.id.gant1); gant2=itemView.findViewById(R.id.gant2); gant3=itemView.findViewById(R.id.gant3); gant4=itemView.findViewById(R.id.gant4); gant5=itemView.findViewById(R.id.gant5); gant6=itemView.findViewById(R.id.gant6); suppBtn=itemView.findViewById(R.id.supprimerBtn); NextProcessBtn=itemView.findViewById(R.id.nextProcessBtn); } } }
Merci pour votre aide car la je bloque
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 public class CartActivity extends AppCompatActivity { int overAllTotalAmount; TextView overAllAmount,test; Toolbar toolbar; RecyclerView recyclerView; List<MyCartModel> cartModelList; MyCartAdapter cartAdapter; private FirebaseAuth auth; private FirebaseFirestore firestore; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cart); auth=FirebaseAuth.getInstance(); firestore=FirebaseFirestore.getInstance(); toolbar=findViewById(R.id.my_cart_toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); /* LocalBroadcastManager.getInstance(this) .registerReceiver(mMessageReceiver,new IntentFilter("MyTotalAmount"));*/ overAllAmount=findViewById(R.id.textView3); recyclerView=findViewById(R.id.cart_rec); recyclerView.setLayoutManager(new LinearLayoutManager(this)); cartModelList=new ArrayList<>(); cartAdapter=new MyCartAdapter(this,cartModelList); recyclerView.setAdapter(cartAdapter); test=findViewById(R.id.textview4); firestore.collection("AddToCart").document(auth.getCurrentUser().getUid()) .collection("User").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { @Override public void onComplete(@NonNull Task<QuerySnapshot> task) { if (task.isSuccessful()){ for (DocumentSnapshot doc :task.getResult().getDocuments()){ String documentID=doc.getId(); MyCartModel myCartModel=doc.toObject(MyCartModel.class); myCartModel.setDocumentId(documentID); cartModelList.add(myCartModel); cartAdapter.notifyDataSetChanged(); } } } }); } public BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { double totalBill = intent.getIntExtra("totalAmount",0); Toast.makeText(context, totalBill+"", Toast.LENGTH_SHORT).show(); overAllAmount.setText("Montant Total :"+Double.valueOf(totalBill)+""); } }; }
.
Partager