0

So, I recently started out with firebase and it's pretty much fun. But now I'm stuck at this. I have this following node in the database, I am confused how the class should look like for this kind of data

enter image description here

My goal is to display username and userID in the recycler view, how can I archive this using FirebaseRecyclerView. Because I think, FirebaseRecyclerView only gets value from the keys to the model class.

Dhiraj kadam
  • 377
  • 3
  • 15
  • **[This](https://stackoverflow.com/questions/49383687/how-can-i-retrieve-data-from-firebase-to-my-adapter/49384849)** is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a `RecyclerView` using `FirebaseRecyclerAdapter`. In this example you'll also find how to structure your model class. – Alex Mamo Jul 12 '18 at 16:07

1 Answers1

-1

It should look like

String Jayyy;
String codedem;
String demom;

// Default Constructor

// getter & setter

But i will not recommend the way in which you are storing the data in your firebase database. You should use unique id (key) and username to be its value.

Raj
  • 2,997
  • 2
  • 12
  • 30
  • The username will go on increasing, that's the issue. If a new user comes onboard , it will add the username to this node – Dhiraj kadam Jul 12 '18 at 15:42
  • I will not recommend the way in which you are storing the data in your firebase database. – Raj Jul 12 '18 at 15:44
  • I've created two nodes, one just stores username and another stores complete users details inside userkey node. so bascially this usernames node is for checking if the new username is unique or not. – Dhiraj kadam Jul 12 '18 at 15:46
  • You should use unique id (key) and username to be its value. – Raj Jul 12 '18 at 15:47
  • Ok, but the issue with that approach is. I'll have to query for all the key to check if the username exists or not. Imagine if my app has 30k users.The reason I kept it as username:key is because I can query for the "username" and check if datasnapshot is empty or not. – Dhiraj kadam Jul 12 '18 at 15:49
  • You can check it by if particular username exits by using query with value of a key. – Raj Jul 12 '18 at 15:52
  • That's the issue, a new user will never know the value of a unique key in which the username exists. So the only naive way is to iterate through all the uuid to check for all the usernames, which is not a good idea. – Dhiraj kadam Jul 12 '18 at 15:57
  • If you are saving the user in firebase authentication, then a user will get a unique key by which you can check that if that key exists or not . – Raj Jul 12 '18 at 16:00
  • Ahh, mate I think you didn't get my point. What I'm saying is suppose I'm the first user onboard and if I choose username as "jhon" and lets say we save it as per your method i.e "ytuBHAfi1VXBkxXj8h5HsHVP1mi2" : "jhon" . after a couple of days you sign up for the same thing and choose to use username as "jhon" now for app to check if the username you're selecting is unique or not it has to iterate through all other uuid's in that node to get the usernames and verify it. – Dhiraj kadam Jul 12 '18 at 16:04
  • Nevermind, I think i need to implement custom recyclerView, Thanks for the help though. – Dhiraj kadam Jul 12 '18 at 16:04