Search code examples
androidfirebasefirebase-realtime-databasefirebaseui

Cant access RecyclerAdapter from inside PopulateViewHolder


I have this

        FirebaseRecyclerAdapter mAdapter = new FirebaseRecyclerAdapter<ChatList, ChatHolder>(ChatList.class, R.layout.chatlistrow, ChatHolder.class, chatRef) {
            @Override
            public void populateViewHolder(ChatHolder chatViewHolder, final ChatList chatList, final int position) {

                //try catch block to catch events of no posts, it will most likely return a null error, so im catching it, else
                //find its exception and catch it

                String fullName = mAdapter.getRef(position).getKey();
                chatViewHolder.setName(fullName);

But the line

String fullName = mAdapter.getRef(position).getKey();

says that mAdapter needs to be declared final. and when I declare it final, it says , mAdapter was never initialized. Solutions, please


Solution

  • You are trying to access yourself. mAdapter == this.

    You can just use this or omit it like:

    String fullName = this.getRef(position).getKey();
    

    or

    String fullName = getRef(position).getKey();