Hello i have saved values in firebase realtime database. but i now i want to fetch it and display it in spinner. see this photo of database firebaseData there are two database named Jokes and Shayari...and they have subcategory in it. I want whenever user enter Jokes in textview then all subcategory of Jokes database should display in spinner and when he enters Shayari then all Shayari's subcategory should display in spinner. Please tell me how can i fetch it on the basis of condition and show them in spinner.
My code of storing the data in firebase.
private void addSubCategory() {
String subcategory = editText.getText().toString().trim();
String parentcategory = spinner.getSelectedItem().toString();
if(parentcategory.equals("Jokes")){
String id = databaseJokes.push().getKey();
SubModel subModel= new SubModel(id, parentcategory, subcategory);
databaseJokes.child(id).setValue(subModel);
Toast.makeText(this, "Jokes Subcategory added", Toast.LENGTH_SHORT).show();
editText.getText().clear();
}
else if(parentcategory.equals("Shayari")){
String id = databaseJokes.push().getKey();
SubModel subModel= new SubModel(id, parentcategory, subcategory);
databaseShayari.child(id).setValue(subModel);
Toast.makeText(this, "Shayari Subcategory added", Toast.LENGTH_SHORT).show();
editText.getText().clear();
}
else if(!TextUtils.isEmpty(subcategory)){
Toast.makeText(this, "Please enter Sub Category", Toast.LENGTH_SHORT).show();
}
}
It is my ModelClass code:
public class SubModel {
String categoryId;
String parentcategory;
String subcategory;
public SubModel(){
}
public SubModel(String categoryId, String parentcategory, String subcategory) {
this.categoryId = categoryId;
this.parentcategory = parentcategory;
this.subcategory = subcategory;
}
public String getCategoryId() {
return categoryId;
}
public String getParentcategory() {
return parentcategory;
}
public String getSubcategory() {
return subcategory;
}
}
Please tell how to fetch them.