firebaserecycleradapter() cannot be applied to FirebaseRecyclerAdapter
Solution 1
The latest version (3.x) of FirebaseUI implements a different method of initializing a FirebaseRecyclerAdapter
than previous versions. From the using the FirebaseRecyclerAdapter documentation:
First, configure the adapter by building
FirebaseRecyclerOptions
. In this case we will continue with our chat example:FirebaseRecyclerOptions<Chat> options = new FirebaseRecyclerOptions.Builder<Chat>() .setQuery(query, Chat.class) .build();
Next create the
FirebaseRecyclerAdapter
object. You should already have aViewHolder
subclass for displaying each item.
So, for your example, you'll need to do something similar to:
FirebaseRecyclerOptions<image_details> options =
new FirebaseRecyclerOptions.Builder<image_details>()
.setQuery(myRef, image_details.class)
.build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<image_details, BlogViewHolder>(options) {
@Override
public BlogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.individual_row, parent, false);
return new BlogViewHolder(view);
}
@Override
protected void onBindViewHolder(BlogViewHolder holder, int position, image_details model) {
// Bind the image_details object to the BlogViewHolder
// ...
}
};
Finally, the FirebaseRecyclerAdapter
uses an event listener to monitor changes to the Firebase query. To begin listening for data, call adapter.startListening()
and adapter.stopListening()
to stop the listener. It's recommended to call these in onStart()
and onStop()
respectively. Further details on this are available in the FirebaseRecyclerAdapter lifecycle documentation.
Solution 2
You missed a method to start the activity.
Add this in onStart()
method:
firebaseRecyclerAdapter.startListening();
Solution 3
Hello your error is due to a missing argument in these () that are found beside this
<image_details, BlogViewHolder>
so you missed one more argument of your BlogViewHolder class so I will add the piece of code and refer your missing argument by a comment in this :
FirebaseRecyclerAdapter<image_details, BlogViewHolder> adapter = new FirebaseRecyclerAdapter<image_details, BlogViewHolder>(
image_details.class,
R.layout.individual_row,
BlogViewHolder.class //see this is missing so you should add it
myRef) {
Sourav Singh
Updated on March 24, 2020Comments
-
Sourav Singh about 4 years
Can someone please tell what's the error in that specific line.
Here is the error message showing.
package com.example.souravkumar.sqaurewallpapers; import android.os.Bundle; import android.os.PersistableBundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.firebase.ui.database.FirebaseRecyclerAdapter; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import com.squareup.picasso.Picasso; /** * Created by Sourav Kumar on 11/3/2017. */ public class popular extends AppCompatActivity { private RecyclerView recyclerView; private DatabaseReference myRef; @Override public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) { super.onCreate(savedInstanceState, persistentState); recyclerView = (RecyclerView) findViewById(R.id.recyclerView); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(this)); myRef = FirebaseDatabase.getInstance().getReference(); FirebaseRecyclerAdapter<image_details, BlogViewHolder> adapter = new FirebaseRecyclerAdapter<image_details, BlogViewHolder>( image_details.class, R.layout.individual_row, myRef) { @Override protected void onBindViewHolder(BlogViewHolder holder, int position, image_details model) { holder.setDate(model.getDate()); holder.setUrl(model.getUrl()); } @Override public BlogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return null; } }; recyclerView.setAdapter(adapter); } public static class BlogViewHolder extends RecyclerView.ViewHolder { TextView textView; ImageView imageView; public BlogViewHolder(View itemView) { super(itemView); textView = (TextView)itemView.findViewById(R.id.date); imageView = (ImageView)itemView.findViewById(R.id.imageView); } public void setDate(Long date) { textView.setText(date.toString()); } public void setUrl(String url) { Picasso.with(itemView.getContext()) .load(url) .resize(50, 50) .centerCrop() .into(imageView); } } }
-
Frank van Puffelen over 6 yearsPlease don't show pictures of code (or of other textual content). Instead edit your question to show the actual code, and include the text of the error message you get. See Creating an MCVE.
-
Sourav Singh over 6 yearsok..but can you please help me here? need help
-
Grimthorr over 6 yearsWhat version of FirebaseUI are you using and is
image_details
a model class? Please share your code as text and the entire error message you receive. -
Sourav Singh over 6 yearsfirebase Ui: compile 'com.firebaseui:firebase-ui-database:3.1.0'
-
Sourav Singh over 6 yearsand yes image_details is model class
-
Sourav Singh over 6 years@Grimthorr I have updated the error message showing, look into the picture
-
Sourav Singh over 6 years@Grimthorr can you please look into my project and tell me where i'm going wrong. I have been struggling from almost a week to retreive data from firebase database to show it on fragment of a tabbed-activity.
-
-
Sourav Singh over 6 yearsBind the image_details object how?
-
Grimthorr over 6 yearsLike you would when creating a normal
RecyclerView
, see creating lists and cards Android documentation. So something like:holder.textView.setText(model.getText());
or whatever method yourimage_details
model has for getting the text that you want to display on the row's TextView. -
Sourav Singh over 6 yearsSir, I am still not able to get output on my fragment screen. can you please look into my project and tell me what's wrong?