Hi I have some issue with calling firebase data from the server.
I can call the single child of data but if I call a nasty child of data(ex: multiple branch of child data), It is not working on kotlin side.
I used ".child()" function on Swift side by just adding ".child()" afterward and it worked on IOS side but I do not understand why the kotlin is not working like that.
Does anyone knows how to solve this problem? I've been searching this problem many days but nobody has a clear solutionenter image description here
Here the issue is of synchronous values, basically onDataChange is called on a different thread.. long story short try calling sectionRecyclerView.adapter line inside the for loop that or this will do the trick.
Related
I have a project that loads a list from the server. This data will eventually be stored into a database, but for now is stored in memory in a MutableLiveData. A RecyclerView's adapter is watching the data and displaying it. So far everything is working as expected, using a FAB the user can post a new entry which will go at the top of the list, on success I get a 200 and here's the main part where I'm getting lost...
When I want to add a single item to a list stored in a LiveData, the observer is unaware of the delta. I currently make a call to RecyclerView.Adapter.notifyDataSetChanged(), though the ideal in my case would be to call notifyItemInserted(0) or in other cases I can see various other notifications. What the best way to do this? The lifecycle architecture library appears to be very well thought of, I assume I'm missing something simple. I can't imagine having to manually perform a diff between the lists?
I have a list of comment objects inside of an object. If I want to add a comment without touching the other comments how would I do that? I have used transactions in the past for editing an integer efficiently but I don't know if I can do that with a list. The end goal is for multiple users to be a ble to add comments at the same time without cutting eachother off (overriding their edits).
Here is an example of my database:
Solved it! Super simple. Just had to add push() to the end of my DatabaseRefercence like so. It gives every comment a key.
commentRef = pollRef.child("comments").push();
commentRef.setValue(comment);
I am using the RecyclerView firebase UI and found nothing realacionando the implementation of the infinite scroll. Today I'm looking for all the data from one node when loading the activity equal to firebase the code example, would leave more optimized this part request, seeking little data to be displayed and go loaded as user navigation.
There may be a workaround by adding a counter for each row in the database and to get them by
orderByChild("counter").startAt(10*n).endAt(10*(n+1));
n: 0 - item_count/10-1
I didnt try it but i believe it can be managed with database parameters.
I need to measure the size/length of an element or list in Firebase but I don't need the real content.
Something like firebase.database().ref("users/").once("length" || "size").then(callback)
ps Javascript SDK
Firebase doesn't have a count operator, so the only way is to download all children or keep a separate <children>_count property in sync. The latter is not a trivial task (see my answer here for one approach and this example Cloud Function), so most often developers likely end up going with the downloads-too-much-data-but-is-trivial approach:
ref.child("messages").on("value", function(snapshot) {
console.log("There are "+snapshot.numChildren()+" messages");
})
A more efficient way to count the children would be to fire a REST call with shallow=true parameter, which will give you just the keys. See In Firebase, is there a way to get the number of children of a node without loading all the node data?
Also found a post which does it a different way...
Object.keys(users).length;
Post: Length of a JavaScript object
I have a Fragment, and once the user presses OK, an Item is added to my database and its ID is added to the ArrayAdapter. Immediately after, the adapter tries to draw the view, but the first time it tries to get its attributes, it returns a null HashMap (it gets drawn properly the following times).
Is there a way to make sure the item is in the table before trying to get its attributes?
Even putting the attribute retrieval into a while loop until it returns a not-null HashMap doesn't work so it doesn't look to be an issue of time.
You need to do Select or GetAttributes with ConsistentRead=true as Amazon SimpleDB supports two read consistency options: eventually consistent read and consistent read. Eventually consistent read is default. For more detail please refer doc. link
Try using AsynTask.
Add item to database in doInBackground.
Read it in postExecute.
You are done.