firebaserecycleradapter() cannot be applied to FirebaseRecyclerAdapter
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.
FirebaseRecyclerAdapter() in FirebaseRecyclerAdapter cannot be applied to [wrong arguments]
You are already using the FirebaseRecyclerOptions
:
FirebaseRecyclerOptions<Category> options =
new FirebaseRecyclerOptions.Builder<Category>()
.setQuery(MenuViewHolder, Category.class)
.build();
The constructor FirebaseRecyclerAdapter
takes a variable of type FirebaseRecyclerOptions
as specified here:
https://github.com/firebase/FirebaseUI-Android/blob/master/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java#L37
Change this:
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(Category.class,R.layout.menu_item,MenuViewHolder.class,category) {
into this:
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
firebaserecycleradapter() in firebaserecycleradapter cannot be applied to
The FirebaseRecyclerAdapter
binds a Query
to a RecyclerView. When data is added, removed, or changed these updates are automatically applied to your UI in real time.
First, configure the adapter by building FirebaseRecyclerOptions
:
FirebaseRecyclerOptions<Category> options =
new FirebaseRecyclerOptions.Builder<Category>()
.setQuery(category, Category.class)
.build();
Next create the FirebaseRecyclerAdapter
object. You should already have a ViewHolder subclass for displaying each item.
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
@Override
public ChatHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Create a new instance of the ViewHolder, in this case we are using a custom
// layout called R.layout.menu_item for each item
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.menu_item, parent, false);
return new MenuViewHolder(view);
}
@Override
protected void onBindViewHolder(MenuViewHolder holder, int position, Category model) {
// Bind the Chat object to the ChatHolder
// ...
}
};
You can find more information here:
https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#firebaseui-for-realtime-database
Why am I getting this error FirebaseRecyclerAdapter() in FirebaseRecyclerAdapter cannot be applied to:
Change this:
FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter <Posts, PostViewHolder> (
Posts.class,
R.layout.posts,
PostViewHolder.class,
mDataBase
)
Into this:
FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter <Posts, PostViewHolder> (options)
In the new version of Firebaseui, the constructor of FirebaseRecyclerAdapter
take a parameter of type FirebaseRecyclerOption
which you already initialized
Check the documentation:
https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#firebaseui-for-realtime-database
FirebaseRecyclerAdapter cannot be applied
From the error, you are giving wrong arguments. Since you already using the FirebaseRecyclerOptions
:
FirebaseRecyclerOptions<Category> options =
new FirebaseRecyclerOptions.Builder<Category>()
.setQuery(MenuViewHolder, Category.class)
.build();
so just change that line to this
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
Error with constructor FirebaseRecyclerAdapter in class FirebaseRecyclerAdapter
You are getting the following error:
error: constructor FirebaseRecyclerAdapter in class FirebaseRecyclerAdapter cannot be applied to given types; required: FirebaseRecyclerOptions found: Class,int,Class,DatabaseReference reason: actual and formal argument lists differ in length where T,VH are type-variables: T extends Object declared in class FirebaseRecyclerAdapter VH extends ViewHolder declared in class FirebaseRecyclerAdapter
Because you have added one of the latest versions of the Firebase-UI library dependency in your build.gradle file. To be able to create a new object of the FirebaseRecyclerAdapter
class, a FirebaseRecyclerOptions
object is required. What you are doing, is passing wrong elements to the constructor. That way of creating the adapter was available in the older versions. Now, to create a new object, pass FirebaseRecyclerOptions
object, as explained in my answer from the following post:
- How can I retrieve data from Firebase to my adapter
Related Topics
Android Webview App Won't Let Video Player Go Full Screen
I am Getting Imei Null in Android Q
How to Create a Circular (Endless) Recyclerview
Getting "Socketexception:Connection Reset by Peer" in Android
Environment.Getexternalstoragedirectory Does Not Return the Path to the Removable Storage
Is There a Listener for When the Webview Displays It's Content
Animating Markers on Google Maps V2
How to Get Recent Tasks on Android "L"
How to Retrieve Style Attributes Programmatically from Styles.Xml
Is There a Better Way to Refresh Webview
Connect an Android Device to a Web Service on Local Host
How to Integrate Eclipse with Gradle in Android Project
How to Securely Store Credentials (Password) in Android Application
How to Convert Views to Bitmaps
How to Get the List of Mounted External Storage of Android Device