0

I am using FirebaseUI's FirebaseRecyclerAdapter as described in github.

But I am getting the error (cannot resolve constructor FirebaseRecyclerAdapter). Tried everything possible but still getting the same error.

Here is my activity

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

My pojo

    String name;

    public Chat() {
    }

    public Chat(String name) {
        this.name = name;

    }

    public String getName() {
        return name;
    }

My ViewHolder

    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);
    }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mehul Kanzariya
  • 888
  • 3
  • 27
  • 58
  • Please provide the error and the link to the github class you are using. You also may want to [edit] your question to show a [mcve] – OneCricketeer May 28 '16 at 15:10
  • @cricket_007 Here is the link (https://github.com/firebase/FirebaseUI-Android/blob/master/app/src/main/java/com/firebase/uidemo/ChatActivity.java) – Mehul Kanzariya May 28 '16 at 15:22
  • 5
    If Android Studio can't find the`FirebaseRecyclerAdapter` class, you're missing this import `import com.firebase.ui.database.FirebaseRecyclerAdapter;` or this dependency `compile 'com.firebaseui:firebase-ui-database:0.4.0'`. – Frank van Puffelen May 28 '16 at 15:23
  • If it can't resolve the constructor, then your object types are incorrect. Check your imports against the documented constructor – OneCricketeer May 28 '16 at 15:39

2 Answers2

3

Change

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

to

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

Done.

pRaNaY
  • 24,642
  • 24
  • 96
  • 146
0

Please view answer here:

Problem is using the old firebase code when creating a reference

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

Migrate to new firebase code and use this instead:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Community
  • 1
  • 1
Higen
  • 77
  • 5
  • I'm using the new reference but still the `populateViewHolder`method is never called, see : http://stackoverflow.com/questions/38263758/populateviewholder-not-executing-with-firebaserecycleradapter-android. Any ideas? Thanks! – raphh Jul 08 '16 at 10:26