我无法在我的RecyclerView中显示我的Firebase数据。我可以将其他活动中的数据添加到Firebase数据库中,我在查看RecyclerView中的数据时遇到了问题。
我创建了一个带有Recipe.class和RecipeViewHolder的FriebaseRecyclerAdapter。如果我的类(名称,评级和描述),我的ViewHolder需要三个部分。我没有在Logcat中收到任何有用的错误。
RecipeList.class
$(document).on('click', 'a[href^="#"]', function (event) {
event.preventDefault();
$('html, body').animate({
scrollTop: $($.attr(this, 'href')).offset().top
}, 1400);
});
$(document).ready(function(){
$(".hamburger").on('click', function(event) {
event.preventDefault();
$(".navigation-list").toggle();
});
});
Recipe.Class
public class RecipeList extends AppCompatActivity {
private RecyclerView recipes;
private FloatingActionButton newRecipeBtn;
private DatabaseReference mRecipeDatabase;
private RecyclerView.LayoutManager mLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipe_list);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mRecipeDatabase = FirebaseDatabase.getInstance().getReference("Recipes");
newRecipeBtn = findViewById(R.id.fab);
recipes = findViewById(R.id.recyclerView);
recipes.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
recipes.setLayoutManager(mLayoutManager);
recipes.setItemAnimator(new DefaultItemAnimator());
recipes.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
FirebaseRecyclerAdapter<Recipe, RecipeViewHolder> adapter = new FirebaseRecyclerAdapter<Recipe, RecipeViewHolder>(
Recipe.class,
R.layout.recycler_list_item,
RecipeViewHolder.class,
mRecipeDatabase
) {
@Override
protected void populateViewHolder(RecipeViewHolder viewHolder, Recipe model, int position) {
viewHolder.setName(model.getName());
viewHolder.setRating(model.getRating());
viewHolder.setDescription(model.getDescription());
}
};
recipes.setAdapter(adapter);
}
public void toRecipeAdd(View view){
Intent intent = new Intent(RecipeList.this, RecipeAdd.class);
startActivity(intent);
}
public static class RecipeViewHolder extends RecyclerView.ViewHolder{
TextView text_name, text_rating, text_description;
public RecipeViewHolder(View itemView){
super(itemView);
text_name = itemView.findViewById(R.id.recipeNameTextView);
text_rating = itemView.findViewById(R.id.recipeRatingTextView);
text_description = itemView.findViewById(R.id.recipeDescriptionTextView);
}
public void setName(String name){
text_name.setText(name);
}
public void setRating(String rating){
text_rating.setText(rating);
}
public void setDescription(String description){
text_description.setText(description);
}
}
}