Skip to content Skip to sidebar Skip to footer

How Can I Resolve Onsucceslistener On A Tablayout Fragment

This is the Database[][1] I am trying to populate the layout I made on a tab layout Fragment with data from a Cloud Firestore database and with the following code the error says th

Solution 1:

You are getting the following error:

addOnSuccessListener (com.google.android.gms.tasks.OnSuccessListener) in Task cannot be applied to (anonymous com.google.android.gms.tasks.OnSuccessListener)

Because you are using DocumentSnapshot instead of using a QuerySnapshot. To solve this, please use the following lines of code:

FirebaseFirestorerootRef= FirebaseFirestore.getInstance();
CollectionReferencephonesRef= rootRef.collection("Phones");
phonesRef.get().addOnCompleteListener(newOnCompleteListener<QuerySnapshot>() {
    @OverridepublicvoidonComplete(@NonNull Task<QuerySnapshot> task) {
        if (task.isSuccessful()) {
            for (QueryDocumentSnapshot document : task.getResult()) {
                Itemsitems= document.toObject(Items.class);

                Stringname1= items.getName();
                Stringcompany1= items.getCompany();
                Stringimage1= items.getImage();

                name.setText(name1);
                company.setText(company1);
                Picasso.get()
                        .load(image1)
                        .fit()
                        .centerCrop()
                        .into(imageView);
            }
        }
    }
});

Now it will work since we are using QuerySnapshot and not the DocumentSnapshot to get the Item objects.

Post a Comment for "How Can I Resolve Onsucceslistener On A Tablayout Fragment"