FirebaseRecyclerAdapter() in FirebaseRecyclerAdapter cannot be applied to [wrong arguments]

前端 未结 2 1369
北海茫月
北海茫月 2021-01-15 12:51

Can someone please tell what\'s the error enter image description here

Here is my code

package com.andisofttechnology.myapplication.Model;

import a         


        
相关标签:
2条回答
  • 2021-01-15 13:23

    You are already using the FirebaseRecyclerOptions:

      FirebaseRecyclerOptions<Category> options =
                new FirebaseRecyclerOptions.Builder<Category>()
                        .setQuery(MenuViewHolder, Category.class)
                        .build();
    

    The constructor FirebaseRecyclerAdapter takes a variable of type FirebaseRecyclerOptions as specified here:

    https://github.com/firebase/FirebaseUI-Android/blob/master/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java#L37

    Change this:

    FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(Category.class,R.layout.menu_item,MenuViewHolder.class,category) {
    

    into this:

    FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
    
    0 讨论(0)
  • 2021-01-15 13:37

    You need implement FirebaseRecyclerAdapter like that:

     FirebaseRecyclerAdapter<YourModel, YourModelViewHolder> firebaseUsersAdapter = null;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    
            FirebaseRecyclerOptions<YourModel> options = new FirebaseRecyclerOptions.Builder<YourModel>()
                    .setQuery(query, YourModel.class)
                    .build();
    
            firebaseUsersAdapter = new FirebaseRecyclerAdapter<YourModel, YourModelViewHolder>(
                    options) {
                @Override
                protected void onBindViewHolder(YourModelViewHolder holder, int position, Users model) {
                    holder.name.setText(model.getName());
                    ...
                }
    
                @Override
                public YourModelViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.R.layout.menu_item, parent, false);
                    return new YourModelViewHolder(view);
                }
            };
    
            mAllUsersRecyclerView.setLayoutManager(new LinearLayoutManager(this));
            mAllUsersRecyclerView.setAdapter(firebaseUsersAdapter);
            firebaseUsersAdapter.startListening();
    

    I hope this helps you.

    0 讨论(0)
提交回复
热议问题