this is my firebase database details:
Everywhere I have found, they get all details to list view. But here I want to get all details using single value. For example: I want to get user's city, address, and dob based on their first name and print it in plain text. So not all person details at once, only for a single person.
If you want to get the single value then, you should use the row key like this,
val query = FirebaseDatabase.getInstance().reference?.child("Users")?.child("{that row key}")
Or if you want to get the first item in that list you can use limitToFirst api like this,
val query = FirebaseDatabase.getInstance().reference?.child("Users")?.limitToFirst(1)
Related
I need to update the data in Firebase database. I have displayed the data in Recyclerview. I need to get the child reference of the position i click in Recyclerview. An not able to use getRef() there to get the reference.
You need to generate a unique key with
String unique = reference.push().getKey();
when saving data to firebase, then you can use that unique key to modify content of that node later.
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Transactions").child(uniqueId)...
You can show your getRef(position) method in your question, maybe another solution can come from there.
Goal: show the list of groups based upon the recent message and when a new message comes, update the chat group list.
Firebase Structure:
Left one structure represents user model: Basically under student key, there is a list of the student then its details along with group ids in which he/she participated.
Right one structure represents the group detail model: Under chat_group key, there is a list of groups with details and also recent message timing.
Solution Tried:
Fetch the group id from the student using the onChildAdded method of firebase DB one by one then fetch its group details using the addListenerForSingleValueEvent method, then store in the list and every time sort it using sort method of array list and then call notifyDataSetChanged method of recyclerview adapter.
Problem with this approach: Too time-consuming and as the number of groups increases processing time also increases.
I think the best solution is to add a new key to the group details model for the students signed up , like that
SignedStudents : "student1 , student2 , student3"
Then you will read data from chat_group directly orderedByChild("recent_message_timeStamp") , then you have to filter it locally to get the groups only related to the specific student to add it to your list like that
String students = model.getStudents();
if (students.contains("student1")) addGroupToYourList();
I develop an android application for students attendance according to their seat numbers. If the student entered his seat number, it will be stored into real time database in fire-base.
Now, what I need to do is to retrieve the empty seat numbers to a list view according to students' information. for example: database has 50 seat numbers entered, but seat number (25) is not in the database then it will be retrieved to the list view.
In general how can I do that with fire-base real time database?
This is how database looks like for one student
You will need to mark seat empty in your db to later only fetch the empty seats. In current situation there is no way to put a query which can retrieve data only for absent students.
Your screenshot is limited so I suggest this structure.
{lectureId}/
seatNumber: {
isEmpty: boolean,
.... your other data
}
Then you will use orderByChild("isEmpty").equalTo(false);
And for querying a set of data from realtime database, have a look at the docs:
https://firebase.google.com/docs/database/web/lists-of-data
you can use a boolean if student is present (present = true).
put this variabble in te object
then you can run a loop on datasnashot for
i < noOfSeats
and show in te ListView with a condition
if (!present){
showInList();
}
Lets assume I have a List of String (ex: List<String>). I want to match all the Strings in the List to a particular attribute already present in the Firebase Database. How do I achieve this, as the equalTo() query only accepts a single String. I also don't want to generate as many queries as the List size. Any help would be much appreciated.
In my project I am getting the employee id values and employee names from the database. I am displaying the names of employees in listview. When I click on the name(here the name textview is a hyperlink) in the listview all the details of that particular employee will be displayed. Based on the employee id when we click on the name that employee details should display. Please help me how to do this in android.
For ex: In general we give like this ----http://sample.com?id=1
How to do that in android?
So based on your question and follow-up comment, what you're gonna want to do is as follows:
Grab the employee name and id as you have already done.
Make an Object that will hold both the employee name and id. Make a toString() method that will return the employee name as a String. The reason for this is because when the ListView is inflated, it defaults to calling the toString() method of its objects (each list entry). Make sure to also have a way to get the employee id from the Object via either a public getter or making the id a public variable itself.
Make the ListView's ArrayList use this Object and set it accordingly.
Then you must use onItemClick to query the site you were referencing in your question. However, when you do query this site, make sure to concatenate the employee id to the end of the URL. Do what you will once you query the site.