Home » Android » populateViewHolder never called – FirebaseRecyclerAdapter

populateViewHolder never called – FirebaseRecyclerAdapter

Posted by: admin November 1, 2017 Leave a comment

Questions:

I’ve been trying to work out why ‘populateViewHolder’ is not called whilst working with FirebaseRecyclerAdapter, the only solutions I have found regard changing the RecyclerView layout to match_parent, which I have done and still not finding ‘populateViewHandler’.

Any ideas what could be causing this issue?
Here is my current code.

UserList.Java

class UserList {
    String Username;
    String Email;
    Long Created;
    public Userlist() {
    }
    public Userlist(String Username, String Email, Long Created) {
        this.Username = username;
        this.Email = email;
        this.Created = created;
    }
    public String getUsername() {
        return Username;
    }
    public void setUsername(String username) {
        Username = username;
    }
    public String getEmail() {
        return Email;
    }
    public void setEmail(String email) {
        Email = email;
    }
    public Long getCreated() {
        return created;
    }
    public void setCreated(Long created) {
        this.created = created;
    }
    public Userlist(String username, String email, Long created) {
        this.Username = username;
        this.Email = email;
        this.created = created;
    }
}

userinfolist.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f5dc">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/userRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

customView.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<TextView
    android:id="@+id/titleTxtView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/createdbytxtview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/titleTxtView"
    android:textSize="18sp"
    android:textStyle="bold"
    android:layout_marginTop="5dp"/>

<TextView
    android:id="@+id/nextsubmission"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Next submission: "
    android:layout_below="@+id/createdbytxtview"
    android:layout_marginTop="5dp"
    android:textSize="18sp"
    android:textStyle="italic"/>

<TextView
    android:id="@+id/userendtxtview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Story ends in: "
    android:layout_below="@+id/nextsubmission"
    android:layout_marginTop="5dp"
    android:textSize="18sp"
    android:textStyle="italic"/>

<ProgressBar
    android:id="@+id/submissionTimer"
    android:layout_width="wrap_content"
    android:layout_height="20dp"
    style="?android:attr/progressBarStyleHorizontal"
    android:indeterminate="false"
    android:max="10"
    android:layout_toRightOf="@+id/nextsubmission"
    android:layout_below="@+id/createdbytxtview"
    android:layout_marginTop="5dp"/>

<ProgressBar
    android:id="@+id/userendtimer"
    android:layout_width="wrap_content"
    android:layout_height="20dp"
    style="?android:attr/progressBarStyleHorizontal"
    android:indeterminate="false"
    android:max="10"
    android:layout_toRightOf="@+id/userendtxtview"
    android:layout_below="@+id/submissionTimer"
    android:layout_marginTop="5dp"
    />

UsersPage.java

public class UsersPage extends AppCompatActivity {

Button homePage;
Button browsePage;
Button logOut;
RecyclerView userDetailsList;
DatabaseReference userDatabase;
private FirebaseRecyclerAdapter<User, UserHolder> fAdapter;
private Query mquery;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.userinfolist);
    this.setTitle("Browse users");

    userDatabase = FirebaseDatabase.getInstance().getReference().child("Users");


    homePage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(UsersPage.this, Home.class));
        }
    });

    browsePage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(UsersPage.this, BrowseUser.class));
        }
    });

    homePage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            FirebaseAuth.getInstance().signOut();
            startActivity(new Intent(UsersPage.this, MainActivity.class));
        }
    });

    userDetailsList = (RecyclerView) findViewById(R.id.userRecyclerView);
    userDetailsList.setLayoutManager(new LinearLayoutManager(UsersPage.this));
    userDetailsList.setHasFixedSize(true);

    Query query = FirebaseDatabase.getInstance()
            .getReference()
            .child("Users")
            .limitToLast(10);

    FirebaseRecyclerOptions<User> options =
            new FirebaseRecyclerOptions.Builder<UserList>()
                    .setQuery(query, UserList.class)
                    .build();


}



public class UserHolder extends RecyclerView.ViewHolder {

    View mView;

    public UserHolder(View itemView) {
        super(itemView);

        mView = itemView;
    }
}

I have been following multiple tutorials to try and figure out and fix this problem, but nothing seems to be working.

FirebaseRecyclerAdapter<UserList, UserHolder> fAdapter = new FireBaseRecycler Adapter

Gives allows the following

FirebaseRecyclerAdapter<UserList, UserHolder> fAdapter = new FirebaseRecyclerAdapter<UserList, UserHolder>() {
    @Override
    protected void onBindViewHolder(UserHolder holder, int position, UserList model) {

    }

    @Override
    public storiesHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

but has no option to give me populateViewHolder, which is shown in all the tutorials of getting FirebaseRecyclerView to work.

As you might have guessed, I’m pretty new to Firebase!
But if you can help me out, big thanks!

EDIT: I read that another possible solution was adding/removing ‘SetHasFixedSize(true)’ which I have tried with and without – which again has not solved the issue

Answers: