Array of Array List in Android to get the Firebase object of object [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question already has an answer here:
How to return DataSnapshot value as a result of a method?
4 answers
I want to calculate the average of each dish by their ratings and display in a bar graph, therefore I need the values of each dish with each thier rating
Example 3 people rated milk as {4,5,3} by each user from the user-specific node linkToJSONTree
I need an ArrayList
which can store multiple lists inside each index of its own listing:
private void letMeCalculate()
{
databaseReference = FirebaseDatabase.getInstance().getReference("/Feedback/"+mdate+"/"+mealtime+"/");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot i : dataSnapshot.getChildren())
{
stringArrayList.add(i.getKey());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
for (String s : stringArrayList)
{
databaseReference = FirebaseDatabase.getInstance().getReference("/Feedback/"+mdate+"/"+mealtime+"/"+s+"/");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren())
{
NewDishRating newDishRating = dataSnapshot1.getValue(NewDishRating.class);
newDishRatingList.add(newDishRating);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}// end of for loop
}// end of function
java android firebase firebase-realtime-database
marked as duplicate by Frank van Puffelen
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 14:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to return DataSnapshot value as a result of a method?
4 answers
I want to calculate the average of each dish by their ratings and display in a bar graph, therefore I need the values of each dish with each thier rating
Example 3 people rated milk as {4,5,3} by each user from the user-specific node linkToJSONTree
I need an ArrayList
which can store multiple lists inside each index of its own listing:
private void letMeCalculate()
{
databaseReference = FirebaseDatabase.getInstance().getReference("/Feedback/"+mdate+"/"+mealtime+"/");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot i : dataSnapshot.getChildren())
{
stringArrayList.add(i.getKey());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
for (String s : stringArrayList)
{
databaseReference = FirebaseDatabase.getInstance().getReference("/Feedback/"+mdate+"/"+mealtime+"/"+s+"/");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren())
{
NewDishRating newDishRating = dataSnapshot1.getValue(NewDishRating.class);
newDishRatingList.add(newDishRating);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}// end of for loop
}// end of function
java android firebase firebase-realtime-database
marked as duplicate by Frank van Puffelen
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 14:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
This is totally different from the one mentioned as duplicate, Since I have query regarding object containing ArrayList of Objects and the one mentioned only says how to take 1D object array using List<>, mine is quite complicated.
– Akshay Bengani
Nov 25 '18 at 15:55
add a comment |
This question already has an answer here:
How to return DataSnapshot value as a result of a method?
4 answers
I want to calculate the average of each dish by their ratings and display in a bar graph, therefore I need the values of each dish with each thier rating
Example 3 people rated milk as {4,5,3} by each user from the user-specific node linkToJSONTree
I need an ArrayList
which can store multiple lists inside each index of its own listing:
private void letMeCalculate()
{
databaseReference = FirebaseDatabase.getInstance().getReference("/Feedback/"+mdate+"/"+mealtime+"/");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot i : dataSnapshot.getChildren())
{
stringArrayList.add(i.getKey());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
for (String s : stringArrayList)
{
databaseReference = FirebaseDatabase.getInstance().getReference("/Feedback/"+mdate+"/"+mealtime+"/"+s+"/");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren())
{
NewDishRating newDishRating = dataSnapshot1.getValue(NewDishRating.class);
newDishRatingList.add(newDishRating);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}// end of for loop
}// end of function
java android firebase firebase-realtime-database
This question already has an answer here:
How to return DataSnapshot value as a result of a method?
4 answers
I want to calculate the average of each dish by their ratings and display in a bar graph, therefore I need the values of each dish with each thier rating
Example 3 people rated milk as {4,5,3} by each user from the user-specific node linkToJSONTree
I need an ArrayList
which can store multiple lists inside each index of its own listing:
private void letMeCalculate()
{
databaseReference = FirebaseDatabase.getInstance().getReference("/Feedback/"+mdate+"/"+mealtime+"/");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot i : dataSnapshot.getChildren())
{
stringArrayList.add(i.getKey());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
for (String s : stringArrayList)
{
databaseReference = FirebaseDatabase.getInstance().getReference("/Feedback/"+mdate+"/"+mealtime+"/"+s+"/");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren())
{
NewDishRating newDishRating = dataSnapshot1.getValue(NewDishRating.class);
newDishRatingList.add(newDishRating);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}// end of for loop
}// end of function
This question already has an answer here:
How to return DataSnapshot value as a result of a method?
4 answers
java android firebase firebase-realtime-database
java android firebase firebase-realtime-database
edited Nov 25 '18 at 10:04
Alex Mamo
48.3k82966
48.3k82966
asked Nov 25 '18 at 9:04
Akshay BenganiAkshay Bengani
107
107
marked as duplicate by Frank van Puffelen
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 14:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Frank van Puffelen
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 14:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
This is totally different from the one mentioned as duplicate, Since I have query regarding object containing ArrayList of Objects and the one mentioned only says how to take 1D object array using List<>, mine is quite complicated.
– Akshay Bengani
Nov 25 '18 at 15:55
add a comment |
This is totally different from the one mentioned as duplicate, Since I have query regarding object containing ArrayList of Objects and the one mentioned only says how to take 1D object array using List<>, mine is quite complicated.
– Akshay Bengani
Nov 25 '18 at 15:55
This is totally different from the one mentioned as duplicate, Since I have query regarding object containing ArrayList of Objects and the one mentioned only says how to take 1D object array using List<>, mine is quite complicated.
– Akshay Bengani
Nov 25 '18 at 15:55
This is totally different from the one mentioned as duplicate, Since I have query regarding object containing ArrayList of Objects and the one mentioned only says how to take 1D object array using List<>, mine is quite complicated.
– Akshay Bengani
Nov 25 '18 at 15:55
add a comment |
2 Answers
2
active
oldest
votes
When using the stringArrayList
outside the callback, it will always be empty due the asynchronous behaviour of the onDataChange()
method. If you want to use the stringArrayList
, you should use it only inside the callback. So to solve this, please move the second for loop inside the onDataChange()
method right after the first for loop ends.
If you need to use that list outside the callback, I recommend you see the last part of my anwser from this post in which I have explained how it can be done using a custom callback. You can also take a look at this video for a better understanding.
Thanks since I get to know about genericTypeIndicator and it works good for me
– Akshay Bengani
Nov 25 '18 at 11:14
@AkshayBenganiGenericTypeIndicator
has nothing to do with asynchronous API's. That's the reason Frank van Puffelen marked this question as a duplicate. GenericTypeIndicator is useful for resolving types for generic collections at runtime. Please don't confuse future visitors.
– Alex Mamo
Jan 8 at 8:34
add a comment |
I got the solution instead of using Array list of Array List I can create genericTypeIndicator follow this link for the solution
https://stackoverflow.com/a/41503903/5867698
1
Using aGenericTypeIndicator
it will not solve the asynchronous problem. GenericTypeIndicator is useful for resolving types for generic collections at runtime, so I don't recommend for this issue this answer for future visitors at all.
– Alex Mamo
Jan 8 at 8:30
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
When using the stringArrayList
outside the callback, it will always be empty due the asynchronous behaviour of the onDataChange()
method. If you want to use the stringArrayList
, you should use it only inside the callback. So to solve this, please move the second for loop inside the onDataChange()
method right after the first for loop ends.
If you need to use that list outside the callback, I recommend you see the last part of my anwser from this post in which I have explained how it can be done using a custom callback. You can also take a look at this video for a better understanding.
Thanks since I get to know about genericTypeIndicator and it works good for me
– Akshay Bengani
Nov 25 '18 at 11:14
@AkshayBenganiGenericTypeIndicator
has nothing to do with asynchronous API's. That's the reason Frank van Puffelen marked this question as a duplicate. GenericTypeIndicator is useful for resolving types for generic collections at runtime. Please don't confuse future visitors.
– Alex Mamo
Jan 8 at 8:34
add a comment |
When using the stringArrayList
outside the callback, it will always be empty due the asynchronous behaviour of the onDataChange()
method. If you want to use the stringArrayList
, you should use it only inside the callback. So to solve this, please move the second for loop inside the onDataChange()
method right after the first for loop ends.
If you need to use that list outside the callback, I recommend you see the last part of my anwser from this post in which I have explained how it can be done using a custom callback. You can also take a look at this video for a better understanding.
Thanks since I get to know about genericTypeIndicator and it works good for me
– Akshay Bengani
Nov 25 '18 at 11:14
@AkshayBenganiGenericTypeIndicator
has nothing to do with asynchronous API's. That's the reason Frank van Puffelen marked this question as a duplicate. GenericTypeIndicator is useful for resolving types for generic collections at runtime. Please don't confuse future visitors.
– Alex Mamo
Jan 8 at 8:34
add a comment |
When using the stringArrayList
outside the callback, it will always be empty due the asynchronous behaviour of the onDataChange()
method. If you want to use the stringArrayList
, you should use it only inside the callback. So to solve this, please move the second for loop inside the onDataChange()
method right after the first for loop ends.
If you need to use that list outside the callback, I recommend you see the last part of my anwser from this post in which I have explained how it can be done using a custom callback. You can also take a look at this video for a better understanding.
When using the stringArrayList
outside the callback, it will always be empty due the asynchronous behaviour of the onDataChange()
method. If you want to use the stringArrayList
, you should use it only inside the callback. So to solve this, please move the second for loop inside the onDataChange()
method right after the first for loop ends.
If you need to use that list outside the callback, I recommend you see the last part of my anwser from this post in which I have explained how it can be done using a custom callback. You can also take a look at this video for a better understanding.
answered Nov 25 '18 at 10:03
Alex MamoAlex Mamo
48.3k82966
48.3k82966
Thanks since I get to know about genericTypeIndicator and it works good for me
– Akshay Bengani
Nov 25 '18 at 11:14
@AkshayBenganiGenericTypeIndicator
has nothing to do with asynchronous API's. That's the reason Frank van Puffelen marked this question as a duplicate. GenericTypeIndicator is useful for resolving types for generic collections at runtime. Please don't confuse future visitors.
– Alex Mamo
Jan 8 at 8:34
add a comment |
Thanks since I get to know about genericTypeIndicator and it works good for me
– Akshay Bengani
Nov 25 '18 at 11:14
@AkshayBenganiGenericTypeIndicator
has nothing to do with asynchronous API's. That's the reason Frank van Puffelen marked this question as a duplicate. GenericTypeIndicator is useful for resolving types for generic collections at runtime. Please don't confuse future visitors.
– Alex Mamo
Jan 8 at 8:34
Thanks since I get to know about genericTypeIndicator and it works good for me
– Akshay Bengani
Nov 25 '18 at 11:14
Thanks since I get to know about genericTypeIndicator and it works good for me
– Akshay Bengani
Nov 25 '18 at 11:14
@AkshayBengani
GenericTypeIndicator
has nothing to do with asynchronous API's. That's the reason Frank van Puffelen marked this question as a duplicate. GenericTypeIndicator is useful for resolving types for generic collections at runtime. Please don't confuse future visitors.– Alex Mamo
Jan 8 at 8:34
@AkshayBengani
GenericTypeIndicator
has nothing to do with asynchronous API's. That's the reason Frank van Puffelen marked this question as a duplicate. GenericTypeIndicator is useful for resolving types for generic collections at runtime. Please don't confuse future visitors.– Alex Mamo
Jan 8 at 8:34
add a comment |
I got the solution instead of using Array list of Array List I can create genericTypeIndicator follow this link for the solution
https://stackoverflow.com/a/41503903/5867698
1
Using aGenericTypeIndicator
it will not solve the asynchronous problem. GenericTypeIndicator is useful for resolving types for generic collections at runtime, so I don't recommend for this issue this answer for future visitors at all.
– Alex Mamo
Jan 8 at 8:30
add a comment |
I got the solution instead of using Array list of Array List I can create genericTypeIndicator follow this link for the solution
https://stackoverflow.com/a/41503903/5867698
1
Using aGenericTypeIndicator
it will not solve the asynchronous problem. GenericTypeIndicator is useful for resolving types for generic collections at runtime, so I don't recommend for this issue this answer for future visitors at all.
– Alex Mamo
Jan 8 at 8:30
add a comment |
I got the solution instead of using Array list of Array List I can create genericTypeIndicator follow this link for the solution
https://stackoverflow.com/a/41503903/5867698
I got the solution instead of using Array list of Array List I can create genericTypeIndicator follow this link for the solution
https://stackoverflow.com/a/41503903/5867698
answered Nov 25 '18 at 11:15
Akshay BenganiAkshay Bengani
107
107
1
Using aGenericTypeIndicator
it will not solve the asynchronous problem. GenericTypeIndicator is useful for resolving types for generic collections at runtime, so I don't recommend for this issue this answer for future visitors at all.
– Alex Mamo
Jan 8 at 8:30
add a comment |
1
Using aGenericTypeIndicator
it will not solve the asynchronous problem. GenericTypeIndicator is useful for resolving types for generic collections at runtime, so I don't recommend for this issue this answer for future visitors at all.
– Alex Mamo
Jan 8 at 8:30
1
1
Using a
GenericTypeIndicator
it will not solve the asynchronous problem. GenericTypeIndicator is useful for resolving types for generic collections at runtime, so I don't recommend for this issue this answer for future visitors at all.– Alex Mamo
Jan 8 at 8:30
Using a
GenericTypeIndicator
it will not solve the asynchronous problem. GenericTypeIndicator is useful for resolving types for generic collections at runtime, so I don't recommend for this issue this answer for future visitors at all.– Alex Mamo
Jan 8 at 8:30
add a comment |
This is totally different from the one mentioned as duplicate, Since I have query regarding object containing ArrayList of Objects and the one mentioned only says how to take 1D object array using List<>, mine is quite complicated.
– Akshay Bengani
Nov 25 '18 at 15:55