我试图在recyclerview中显示图像和textview,但是我找不到问题,我将照片和文本放在firebase中的“”是什么问题?
Java
Input: 50
50, [255,128,0]
Input: 33
33, [168,171,0]
有模型类
Java
MoviesRv.setLayoutManager(new LinearLayoutManager(HomeActivity.this, LinearLayout.HORIZONTAL,false));
reference = FirebaseDatabase.getInstance().getReference("Data");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
List<Movie> first_tMovie = new ArrayList<>();
for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
{
Movie p = dataSnapshot1.getValue(Movie.class);
first_tMovie.add(p);
}
MovieAdapter movieAdapter = new MovieAdapter(HomeActivity.this,first_tMovie);
MoviesRv.setAdapter(movieAdapter)
答案 0 :(得分:0)
这是因为您不能将Movie.class的参数传递给value参数:
改为更改此内容:
Movie p = dataSnapshot1.getValue(Movie.class);
对此:
Movie p = (Movie)dataSnapshot1.getValue();
或正确传递参数,即
Movie p = new Movie(datasnapshot1.child("x").getValue(),datasnapshot1.child("thumbnail").getValue());