how to push data in firebase using orderByValue in android?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
In my code I push data using child considered as (ID), and every onfresh method it will update values (val1, val2, val3) using setvalue method. But while pushing data it stored data in ascending order referring to ID (every time ID is create as child, if child not exists, if is exist is will update the value). So I want store such type of data, when data is push then, data must be store in sequentially like mdatarefrence.push()
method works.
mFireDatabase = FirebaseDatabase.getInstance();
databaseReference = mFireDatabase.getReference().child("Matches").child("Match_"+getmatch_id).child("commentry");
mCommentryAdpter = new CommentryAdpter( getContext(),R.layout.commentrytuple, applications);
commentry.setAdapter(mCommentryAdpter);
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
{
mCommentryEntry = dataSnapshot.getValue(CommentryEntry.class);
mCommentryAdpter.add(mCommentryEntry);
ListUtils.setDynamicHeight(commentry);
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
Condition while pushing data
mCommentryEntry = new CommentryEntry(va1,val2,val3);
databaseReference.child(ID).setValue(mCommentryEntry);
android firebase firebase-realtime-database
add a comment |
In my code I push data using child considered as (ID), and every onfresh method it will update values (val1, val2, val3) using setvalue method. But while pushing data it stored data in ascending order referring to ID (every time ID is create as child, if child not exists, if is exist is will update the value). So I want store such type of data, when data is push then, data must be store in sequentially like mdatarefrence.push()
method works.
mFireDatabase = FirebaseDatabase.getInstance();
databaseReference = mFireDatabase.getReference().child("Matches").child("Match_"+getmatch_id).child("commentry");
mCommentryAdpter = new CommentryAdpter( getContext(),R.layout.commentrytuple, applications);
commentry.setAdapter(mCommentryAdpter);
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
{
mCommentryEntry = dataSnapshot.getValue(CommentryEntry.class);
mCommentryAdpter.add(mCommentryEntry);
ListUtils.setDynamicHeight(commentry);
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
Condition while pushing data
mCommentryEntry = new CommentryEntry(va1,val2,val3);
databaseReference.child(ID).setValue(mCommentryEntry);
android firebase firebase-realtime-database
add a comment |
In my code I push data using child considered as (ID), and every onfresh method it will update values (val1, val2, val3) using setvalue method. But while pushing data it stored data in ascending order referring to ID (every time ID is create as child, if child not exists, if is exist is will update the value). So I want store such type of data, when data is push then, data must be store in sequentially like mdatarefrence.push()
method works.
mFireDatabase = FirebaseDatabase.getInstance();
databaseReference = mFireDatabase.getReference().child("Matches").child("Match_"+getmatch_id).child("commentry");
mCommentryAdpter = new CommentryAdpter( getContext(),R.layout.commentrytuple, applications);
commentry.setAdapter(mCommentryAdpter);
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
{
mCommentryEntry = dataSnapshot.getValue(CommentryEntry.class);
mCommentryAdpter.add(mCommentryEntry);
ListUtils.setDynamicHeight(commentry);
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
Condition while pushing data
mCommentryEntry = new CommentryEntry(va1,val2,val3);
databaseReference.child(ID).setValue(mCommentryEntry);
android firebase firebase-realtime-database
In my code I push data using child considered as (ID), and every onfresh method it will update values (val1, val2, val3) using setvalue method. But while pushing data it stored data in ascending order referring to ID (every time ID is create as child, if child not exists, if is exist is will update the value). So I want store such type of data, when data is push then, data must be store in sequentially like mdatarefrence.push()
method works.
mFireDatabase = FirebaseDatabase.getInstance();
databaseReference = mFireDatabase.getReference().child("Matches").child("Match_"+getmatch_id).child("commentry");
mCommentryAdpter = new CommentryAdpter( getContext(),R.layout.commentrytuple, applications);
commentry.setAdapter(mCommentryAdpter);
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
{
mCommentryEntry = dataSnapshot.getValue(CommentryEntry.class);
mCommentryAdpter.add(mCommentryEntry);
ListUtils.setDynamicHeight(commentry);
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
Condition while pushing data
mCommentryEntry = new CommentryEntry(va1,val2,val3);
databaseReference.child(ID).setValue(mCommentryEntry);
android firebase firebase-realtime-database
android firebase firebase-realtime-database
edited Nov 23 '18 at 21:05
Frank van Puffelen
248k31396423
248k31396423
asked Nov 23 '18 at 20:31
Shivam GuptaShivam Gupta
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you want to generate a push ID, call push()
before calling setValue()
:
mCommentryEntry = new CommentryEntry(va1,val2,val3);
databaseReference.child(ID).push().setValue(mCommentryEntry);
Note that I'm not sure what ID
is in your code snippet, so I just copied it here. If you want a unique, chronologically ordered, child key under databaseReference
, you'd just call:
databaseReference.push().setValue(mCommentryEntry);
i respect your answer but how will i update key's which genrerated by firebase? please tell me if key is exist it will be update value else it is add to arrayadpter.
– Shivam Gupta
Nov 23 '18 at 21:16
sir please give me your gmailid or whatsapp number i want to some need from you relation with realtime firebase. i am waiting for your replay... thank you
– Shivam Gupta
Nov 23 '18 at 21:22
2
That's not how Stack Overflow works Shivam. But at this point it is also unclear to me what you're trying to accomplish. Here are the options for generating child nodes: 1) If you want to control the key used yourself, usechild(keyThatYouWant).setValue(...)
. 2) If you want Firebase to generate a unique, chronological key for you usepush().setValue(...)
.
– Frank van Puffelen
Nov 23 '18 at 21:25
thnkxx for reply but i am pushing value in firebase using option first , child(keyThatYouWant).setValue(...) but in this case , data stored in database in ascending order reffering to (KeyThatYouWant). means instead of (KeyThatYouWant) i use Unique (ID) and reffering to Unique (ID) data store in Acsending order , i want achive that data must be stored chronologically ordered but data stored in acsending order. sir please help me, i am waiting for your reply
– Shivam Gupta
Nov 24 '18 at 8:18
If you want to determine your own keys, but still want to retrieve the nodes in chronological order, add a timestamp to each node, and then retrieve the nodes withref.orderByChild("timestamp")
.
– Frank van Puffelen
Nov 24 '18 at 14:53
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452636%2fhow-to-push-data-in-firebase-using-orderbyvalue-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to generate a push ID, call push()
before calling setValue()
:
mCommentryEntry = new CommentryEntry(va1,val2,val3);
databaseReference.child(ID).push().setValue(mCommentryEntry);
Note that I'm not sure what ID
is in your code snippet, so I just copied it here. If you want a unique, chronologically ordered, child key under databaseReference
, you'd just call:
databaseReference.push().setValue(mCommentryEntry);
i respect your answer but how will i update key's which genrerated by firebase? please tell me if key is exist it will be update value else it is add to arrayadpter.
– Shivam Gupta
Nov 23 '18 at 21:16
sir please give me your gmailid or whatsapp number i want to some need from you relation with realtime firebase. i am waiting for your replay... thank you
– Shivam Gupta
Nov 23 '18 at 21:22
2
That's not how Stack Overflow works Shivam. But at this point it is also unclear to me what you're trying to accomplish. Here are the options for generating child nodes: 1) If you want to control the key used yourself, usechild(keyThatYouWant).setValue(...)
. 2) If you want Firebase to generate a unique, chronological key for you usepush().setValue(...)
.
– Frank van Puffelen
Nov 23 '18 at 21:25
thnkxx for reply but i am pushing value in firebase using option first , child(keyThatYouWant).setValue(...) but in this case , data stored in database in ascending order reffering to (KeyThatYouWant). means instead of (KeyThatYouWant) i use Unique (ID) and reffering to Unique (ID) data store in Acsending order , i want achive that data must be stored chronologically ordered but data stored in acsending order. sir please help me, i am waiting for your reply
– Shivam Gupta
Nov 24 '18 at 8:18
If you want to determine your own keys, but still want to retrieve the nodes in chronological order, add a timestamp to each node, and then retrieve the nodes withref.orderByChild("timestamp")
.
– Frank van Puffelen
Nov 24 '18 at 14:53
|
show 1 more comment
If you want to generate a push ID, call push()
before calling setValue()
:
mCommentryEntry = new CommentryEntry(va1,val2,val3);
databaseReference.child(ID).push().setValue(mCommentryEntry);
Note that I'm not sure what ID
is in your code snippet, so I just copied it here. If you want a unique, chronologically ordered, child key under databaseReference
, you'd just call:
databaseReference.push().setValue(mCommentryEntry);
i respect your answer but how will i update key's which genrerated by firebase? please tell me if key is exist it will be update value else it is add to arrayadpter.
– Shivam Gupta
Nov 23 '18 at 21:16
sir please give me your gmailid or whatsapp number i want to some need from you relation with realtime firebase. i am waiting for your replay... thank you
– Shivam Gupta
Nov 23 '18 at 21:22
2
That's not how Stack Overflow works Shivam. But at this point it is also unclear to me what you're trying to accomplish. Here are the options for generating child nodes: 1) If you want to control the key used yourself, usechild(keyThatYouWant).setValue(...)
. 2) If you want Firebase to generate a unique, chronological key for you usepush().setValue(...)
.
– Frank van Puffelen
Nov 23 '18 at 21:25
thnkxx for reply but i am pushing value in firebase using option first , child(keyThatYouWant).setValue(...) but in this case , data stored in database in ascending order reffering to (KeyThatYouWant). means instead of (KeyThatYouWant) i use Unique (ID) and reffering to Unique (ID) data store in Acsending order , i want achive that data must be stored chronologically ordered but data stored in acsending order. sir please help me, i am waiting for your reply
– Shivam Gupta
Nov 24 '18 at 8:18
If you want to determine your own keys, but still want to retrieve the nodes in chronological order, add a timestamp to each node, and then retrieve the nodes withref.orderByChild("timestamp")
.
– Frank van Puffelen
Nov 24 '18 at 14:53
|
show 1 more comment
If you want to generate a push ID, call push()
before calling setValue()
:
mCommentryEntry = new CommentryEntry(va1,val2,val3);
databaseReference.child(ID).push().setValue(mCommentryEntry);
Note that I'm not sure what ID
is in your code snippet, so I just copied it here. If you want a unique, chronologically ordered, child key under databaseReference
, you'd just call:
databaseReference.push().setValue(mCommentryEntry);
If you want to generate a push ID, call push()
before calling setValue()
:
mCommentryEntry = new CommentryEntry(va1,val2,val3);
databaseReference.child(ID).push().setValue(mCommentryEntry);
Note that I'm not sure what ID
is in your code snippet, so I just copied it here. If you want a unique, chronologically ordered, child key under databaseReference
, you'd just call:
databaseReference.push().setValue(mCommentryEntry);
answered Nov 23 '18 at 21:07
Frank van PuffelenFrank van Puffelen
248k31396423
248k31396423
i respect your answer but how will i update key's which genrerated by firebase? please tell me if key is exist it will be update value else it is add to arrayadpter.
– Shivam Gupta
Nov 23 '18 at 21:16
sir please give me your gmailid or whatsapp number i want to some need from you relation with realtime firebase. i am waiting for your replay... thank you
– Shivam Gupta
Nov 23 '18 at 21:22
2
That's not how Stack Overflow works Shivam. But at this point it is also unclear to me what you're trying to accomplish. Here are the options for generating child nodes: 1) If you want to control the key used yourself, usechild(keyThatYouWant).setValue(...)
. 2) If you want Firebase to generate a unique, chronological key for you usepush().setValue(...)
.
– Frank van Puffelen
Nov 23 '18 at 21:25
thnkxx for reply but i am pushing value in firebase using option first , child(keyThatYouWant).setValue(...) but in this case , data stored in database in ascending order reffering to (KeyThatYouWant). means instead of (KeyThatYouWant) i use Unique (ID) and reffering to Unique (ID) data store in Acsending order , i want achive that data must be stored chronologically ordered but data stored in acsending order. sir please help me, i am waiting for your reply
– Shivam Gupta
Nov 24 '18 at 8:18
If you want to determine your own keys, but still want to retrieve the nodes in chronological order, add a timestamp to each node, and then retrieve the nodes withref.orderByChild("timestamp")
.
– Frank van Puffelen
Nov 24 '18 at 14:53
|
show 1 more comment
i respect your answer but how will i update key's which genrerated by firebase? please tell me if key is exist it will be update value else it is add to arrayadpter.
– Shivam Gupta
Nov 23 '18 at 21:16
sir please give me your gmailid or whatsapp number i want to some need from you relation with realtime firebase. i am waiting for your replay... thank you
– Shivam Gupta
Nov 23 '18 at 21:22
2
That's not how Stack Overflow works Shivam. But at this point it is also unclear to me what you're trying to accomplish. Here are the options for generating child nodes: 1) If you want to control the key used yourself, usechild(keyThatYouWant).setValue(...)
. 2) If you want Firebase to generate a unique, chronological key for you usepush().setValue(...)
.
– Frank van Puffelen
Nov 23 '18 at 21:25
thnkxx for reply but i am pushing value in firebase using option first , child(keyThatYouWant).setValue(...) but in this case , data stored in database in ascending order reffering to (KeyThatYouWant). means instead of (KeyThatYouWant) i use Unique (ID) and reffering to Unique (ID) data store in Acsending order , i want achive that data must be stored chronologically ordered but data stored in acsending order. sir please help me, i am waiting for your reply
– Shivam Gupta
Nov 24 '18 at 8:18
If you want to determine your own keys, but still want to retrieve the nodes in chronological order, add a timestamp to each node, and then retrieve the nodes withref.orderByChild("timestamp")
.
– Frank van Puffelen
Nov 24 '18 at 14:53
i respect your answer but how will i update key's which genrerated by firebase? please tell me if key is exist it will be update value else it is add to arrayadpter.
– Shivam Gupta
Nov 23 '18 at 21:16
i respect your answer but how will i update key's which genrerated by firebase? please tell me if key is exist it will be update value else it is add to arrayadpter.
– Shivam Gupta
Nov 23 '18 at 21:16
sir please give me your gmailid or whatsapp number i want to some need from you relation with realtime firebase. i am waiting for your replay... thank you
– Shivam Gupta
Nov 23 '18 at 21:22
sir please give me your gmailid or whatsapp number i want to some need from you relation with realtime firebase. i am waiting for your replay... thank you
– Shivam Gupta
Nov 23 '18 at 21:22
2
2
That's not how Stack Overflow works Shivam. But at this point it is also unclear to me what you're trying to accomplish. Here are the options for generating child nodes: 1) If you want to control the key used yourself, use
child(keyThatYouWant).setValue(...)
. 2) If you want Firebase to generate a unique, chronological key for you use push().setValue(...)
.– Frank van Puffelen
Nov 23 '18 at 21:25
That's not how Stack Overflow works Shivam. But at this point it is also unclear to me what you're trying to accomplish. Here are the options for generating child nodes: 1) If you want to control the key used yourself, use
child(keyThatYouWant).setValue(...)
. 2) If you want Firebase to generate a unique, chronological key for you use push().setValue(...)
.– Frank van Puffelen
Nov 23 '18 at 21:25
thnkxx for reply but i am pushing value in firebase using option first , child(keyThatYouWant).setValue(...) but in this case , data stored in database in ascending order reffering to (KeyThatYouWant). means instead of (KeyThatYouWant) i use Unique (ID) and reffering to Unique (ID) data store in Acsending order , i want achive that data must be stored chronologically ordered but data stored in acsending order. sir please help me, i am waiting for your reply
– Shivam Gupta
Nov 24 '18 at 8:18
thnkxx for reply but i am pushing value in firebase using option first , child(keyThatYouWant).setValue(...) but in this case , data stored in database in ascending order reffering to (KeyThatYouWant). means instead of (KeyThatYouWant) i use Unique (ID) and reffering to Unique (ID) data store in Acsending order , i want achive that data must be stored chronologically ordered but data stored in acsending order. sir please help me, i am waiting for your reply
– Shivam Gupta
Nov 24 '18 at 8:18
If you want to determine your own keys, but still want to retrieve the nodes in chronological order, add a timestamp to each node, and then retrieve the nodes with
ref.orderByChild("timestamp")
.– Frank van Puffelen
Nov 24 '18 at 14:53
If you want to determine your own keys, but still want to retrieve the nodes in chronological order, add a timestamp to each node, and then retrieve the nodes with
ref.orderByChild("timestamp")
.– Frank van Puffelen
Nov 24 '18 at 14:53
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452636%2fhow-to-push-data-in-firebase-using-orderbyvalue-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown