无法从populateViewholder内部访问回收层



我有这个

        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);

但是线

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

mAdapter需要被宣布为最终。当我宣布最终时,mAdapter从未初始化。解决方案请

您正在尝试访问自己。 mAdapter == this

您只能使用this或省略以下内容:

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

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

相关内容

  • 没有找到相关文章

最新更新