In beginning 1-5 time checking the checkbox, it was no issue happening. After that there are some checkboxes is follow check or uncheck when I check or uncheck a checkbox.
I have to some research for this question but I did not know how to implement it in my code.
protected void onBindViewHolder(@NonNull final FirebaseCartProductViewHolder firebaseCartProductViewHolder,int i,@NonNull final Cart cart){
firebaseCartProductViewHolder.itemId.setText(cart.getItemID());
firebaseCartProductViewHolder.productName.setText(cart.getProductName());
firebaseCartProductViewHolder.productPrice.setText(cart.getPrice());
Picasso.with(getActivity()).load(cart.getImageURL()).into(firebaseCartProductViewHolder.productImage);
databaseReference = FirebaseDatabase.getInstance().getReference().child("Account").child(user).child("cart").child(firebaseCartProductViewHolder.itemId.getText().toString());
databaseReference.keepSynced(true);
databaseReference.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot){
if(dataSnapshot != null && dataSnapshot.exists()){
String status = dataSnapshot.child("status").getValue().toString();
String str1 = "check";
if(status.equals(str1))
{
firebaseCartProductViewHolder.check1.setChecked(true);
}
else
{
firebaseCartProductViewHolder.check1.setChecked(false);
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError){
}
});
firebaseCartProductViewHolder.check1.setOnCheckedChangeListener(null);
firebaseCartProductViewHolder.check1.isChecked();
firebaseCartProductViewHolder.check1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
DatabaseReference dbref;
dbref = FirebaseDatabase.getInstance().getReference().child("Account").child(user).child("cart").child(firebaseCartProductViewHolder.itemId.getText().toString());
System.out.println(firebaseCartProductViewHolder.itemId.getText().toString());
if(firebaseCartProductViewHolder.check1.isChecked()) {
dbref.child("status").setValue("check");
}
else
{
dbref.child("status").setValue("pending check");
}
}
});
/*firebaseCartProductViewHolder.check1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
DatabaseReference dbref;
dbref = FirebaseDatabase.getInstance().getReference().child("Account").child(user).child("cart").child(firebaseCartProductViewHolder.itemId.getText().toString());
System.out.println(firebaseCartProductViewHolder.itemId.getText().toString());
if(firebaseCartProductViewHolder.check1.isChecked()) {
dbref.child("status").setValue("check");
}
else
{
dbref.child("status").setValue("pending check");
}
}
});*/
}
How to overcome this? I guess there was a problem to save the state of the checkbox????
Aucun commentaire:
Enregistrer un commentaire