I cant see any FirebaseRecyclerAdapter items on my layout
The tutorial that you are following is wrong. To solve your problem, please consider following these steps.
Move all the code from the
onStart()
method insideonCreate()
method except these two lines of code:super.onStart();
firebaseAuth.addAuthStateListener(authStateListener);Make your
firebaseRecyclerAdapter
varaible global:private FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter;
Remove
FirebaseRecyclerAdapter<Blog, BlogViewHolder>
from theonCreate()
method.Add the following lines of code in the
onStart()
andonStop()
methods.@Override
protected void onStart() {
super.onStart();
firebaseRecyclerAdapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
if(firebaseRecyclerAdapter != null) {
firebaseRecyclerAdapter.stopListening();
}
}The most important thing is to remove the
static
keyword from your class declaration. Should be only:public class PostViewHolder extends RecyclerView.ViewHolder {}
FirebaseRecyclerAdapter is not displaying data in my RecyclerView layout
com.google.firebase.database.DatabaseException: Failed to convert
value of type java.lang.Long to String
First of all, it's should be a InvocationTargetException
[according your database structure] as you try to cast Long
as String
in your model. Try to update your model like below:
public class Films {
public String name;
public int year;
....
}
Then, You should set LayoutManager
to your RecyclerView
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
mFilmsList.setLayoutManager(linearLayoutManager);
Update: You have to update your onBindViewHolder
to convert int
to String before setting it to TextView using String.valueOf
@Override
protected void onBindViewHolder(FilmsViewHolder filmsViewHolder, int i, Films films) {
filmsViewHolder.mFilmName.setText(films.getName());
filmsViewHolder.mFilmYear.setText(String.valueOf(films.getYear()));
}
Firebase Recycler Adapter is not showing anything
As I see in your database, your fields do not corespond to those from your model class. To solve this, delete the old data, add fresh one and your problem will be solved.
As I see in your code, you are using for the declaration of your CustDetailHolder
class, the static
keyword, which is wrong. You only need:
public class CustDetailHolder extends RecyclerView.ViewHolder
Also remove ButterKnife.bind(this,mView);
as I see that you don't use it in your code.
Android FirebaseRecyclerAdapter is not populating RecyclerView
add this line:
firebaseRecyclerAdapter.startListening();
under this:
mRecyclerView.setAdapter(firebaseRecyclerAdapter);
inside searchFriends() method.
Unable to use custom layout in FirebaseRecyclerAdapter (Android Studio)
After talking with OP in chat, he exported the JSON and the parent node had the name Blog
and not Blog_images
, so I told him to change this:
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("Blog_Images");
into this:
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("Blog");
FirebaseRecyclerAdapter with empty view
Here is what I would try. First check out the accepted answer to the question linked below. It provides some very good insight into how Firebase queries work. I'd consider the info trusted since the answer is by someone on the Firebase team:
How to separate initial data load from incremental children with Firebase?
So, based on the answer to the question linked above and the fact that the FirebaseRecyclerAdapter
is backed by a FirebaseArray
which is populated using a ChildEventListener
I would add a Single value event listener on the same database reference used to populate your FirebaseRecyclerAdapter
. Something like this:
//create database reference that will be used for both the
//FirebaseRecyclerAdapter and the single value event listener
dbRef = FirebaseDatabase.getInstance().getReference();
//setup FirebaseRecyclerAdapter
mAdapter = new FirebaseRecyclerAdapter<Model, YourViewHolder>(
Model.class, R.layout.your_layout, YourViewHolder.class, dbRef) {
@Override
public void populateViewHolder(YourViewHolder holder, Model model, int position){
//your code for populating each recycler view item
};
mRecyclerView.setAdapter(mAdapter);
//add the listener for the single value event that will function
//like a completion listener for initial data load of the FirebaseRecyclerAdapter
dbRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//onDataChange called so remove progress bar
//make a call to dataSnapshot.hasChildren() and based
//on returned value show/hide empty view
//use helper method to add an Observer to RecyclerView
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
That would handle the initial setup of the RecyclerView. When onDataChange
is called on the single value event listener use a helper method to add an observer to the FirebaseRecyclerAdapter to handle any subsequent additions/deletions to database location.
mObserver = new RecyclerView.AdapterDataObserver() {
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
//perform check and show/hide empty view
}
@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
//perform check and show/hide empty view
}
};
mAdapter.registerAdapterDataObserver(mObserver);
FirebaseRecyclerAdapter not showing data in Fragment
Same problem occurred me. Simply remove the service_list.setHasFixedSize(true)
.
Related Topics
Sending Http Post Request with Android
How to Blur Background Images in Android
Convert Normal Java Array or Arraylist to JSON Array in Android
Rotate Marker and Move Animation on Map Like Uber Android
Kotlin-Android: Unresolved Reference Databinding
Intellij Build Error Context Mismatch
What Is the Correct Way to Do Inserts/Updates/Deletes in Android SQLitedatabase Using a Query String
Simple Sso - Using Custom Authentication - Cas or Some Oauth or Openid Server
Python: How to Execute a Jar File Through a Python Script
Converting Utf-8 to Iso-8859-1 in Java - How to Keep It as Single Byte
Android Resource Not Found Exception
How to Show Ellipses on My Textview If It Is Greater Than the 1 Line
Click Is Not Working on the Listitem Listview Android
How to Implement the Android Actionbar Back Button
Use Startactivityforresult from Non-Activity
Multiple Dex Files Define <My Package>/Buildconfig, Can't Find the Cause: