I am sending "Appetizers and Snacks" which is in name
key from one activity 1 to activity 2.
In activity 2,the data received is simply :
intent = getIntent();
String received_id = intent.getStringExtra("cat_id");
Log.e("ID received is", received_id);
Output is :
ID received is : Appetizers and Snacks
With the Help of this value, I'm trying to read the Node recipes
and display all the data in their Respective Views.
I only want to know , how can I get to the recipes
node. I tried this till now :
query = FirebaseDatabase.getInstance().getReference("All Categories").orderByChild("name").equalTo(received_id);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Log.e("data", String.valueOf(dataSnapshot));
if (dataSnapshot.exists()) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.child("recipes").getChildren()) {
Log.e("data final is ", String.valueOf(dataSnapshot1.getValue()));
DetailModel p = dataSnapshot1.getValue(DetailModel.class);
detailModelList.add(p);
}
detailAdapter = new DetailAdapter(DetailCategory.this, detailModelList);
recyclerView.setAdapter(detailAdapter);
progressBar.setVisibility(View.INVISIBLE);
} else {
Toast.makeText(DetailCategory.this, "No data available !", Toast.LENGTH_SHORT).show();
Log.e("No data available !", "No data available !");
progressBar.setVisibility(View.INVISIBLE);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(DetailCategory.this, databaseError.getDetails(), Toast.LENGTH_SHORT).show();
}
});
recyclerView.setLayoutManager(new GridLayoutManager(DetailCategory.this, 2));
The
Log.e("data", String.valueOf(datasnapshot))
gives this Output :
DataSnapshot { key = All Categories, value = {0={image=https://i.imgur.com/0toOJMa.jpg, recipes={randomkey={image=https://i.ibb.co/gvH8Vp2/5f6fg0l8-keraal-roast-chicken-62.png, servings=4 servings, ingredients="complete Ingredients here"}}, name=Appetizers and Snacks}} }
My DetailModel class is a simple class :
public DetailModel() {
}
String image,title, time,servings,ingredients,steps;
public DetailModel(Integer id, String image, String title, String time, String servings, String ingredients, String steps) {
this.id = id;
this.image = image;
this.title = title;
this.time = time;
this.servings = servings;
this.ingredients = ingredients;
this.steps = steps;
}
public Integer getId() {
return id;
}
public String getImage() {
return image;
}
public String getTitle() {
return title;
}
public String getTime() {
return time;
}
public String getServings() {
return servings;
}
public String getIngredients() {
return ingredients;
}
public String getSteps() {
return steps;
}
But every time there is no data Received in the App, Completely Blank, even the Else conditions are not executing.
it doesn't reach if (dataSnapshot.exists()) { and none of the code inside is executed. Since, I also checked with settings logs , nothing is found in Logcat as well . Any Tips , why this is happening ?
EDIT : i did as Frank Recommended, Still there is no data in the App
Please Guide me reading this nested Data.