尝试使用 FirebaseUI 时"cannot resolve constructor FirebaseRecyclerAdapter"



我正在使用 FirebaseUI 的 FirebaseRecyclerAdapter,如 github 中所述。

但是我收到错误(无法解析构造函数FirebaseRecyclerAdapter)。尝试了一切可能的方法,但仍然得到相同的错误。

这是我的活动

Firebase ref = new Firebase("https://myapp.firebaseio.com/shoplist");
RecyclerView recyclerView;
String enteredShopName;
private FirebaseRecyclerAdapter<Chat, ChatHolder> mRecyclerViewAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            createDialog();
        }
    });
}
@Override
protected void onStart() {
    super.onStart();
    attachRecyclerViewAdapter();
}
private void attachRecyclerViewAdapter() {
    mRecyclerViewAdapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(
            Chat.class, R.layout.message, ChatHolder.class, ref) {
        @Override
        public void populateViewHolder(ChatHolder chatView, Chat chat, int position) {
            chatView.setName(chat.getName());

        }
    };
               }
    });
    mRecyclerViewAdapter.setAdapter(mRecyclerViewAdapter);
}
private void createDialog() {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    LayoutInflater inflater = this.getLayoutInflater();
    final View dialogView = inflater.inflate(R.layout.addshop_dialog, null);
    dialogBuilder.setView(dialogView);
    final EditText randeephooda = (EditText) dialogView.findViewById(R.id.et_shopName);
    enteredShopName = randeephooda.getText().toString();
    dialogBuilder.setTitle("Add Shop");
    dialogBuilder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            //do something with edt.getText().toString();

            Chat chat = new Chat(enteredShopName);
            ref.push().setValue(chat);
        }
    });
    dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            //pass
        }
    });
    AlertDialog b = dialogBuilder.create();
    b.show();
}

我的波乔

    String name;
    public Chat() {
    }
    public Chat(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }

我的视筒

    public ChatHolder(View itemView) {
        super(itemView);
        mView = itemView;
    }
    public void setName(String name) {
        TextView field = (TextView) mView.findViewById(R.id.shoprecyclerview_textView);
        field.setText(name);
    }
}

更改

mRecyclerViewAdapter.setAdapter(mRecyclerViewAdapter);//this line caused error

recyclerView.setAdapter(mRecyclerViewAdapter);//Need to set adapter to the recyclerview

做。

请在此处查看答案:

创建引用时使用旧的 Firebase 代码时出现问题

Firebase ref = new Firebase("https://myapp.firebaseio.com/shoplist");

迁移到新的 Firebase 代码并改用以下内容:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();

相关内容

  • 没有找到相关文章

最新更新