我尝试运行代码,但在模拟器上却什么也没有显示,我还使用firebase来获取包括图像和文本的数据
//send Query to FirebaseDatabase
mFirebaseDatabase = FirebaseDatabase.getInstance();
mRef = mFirebaseDatabase.getReference().child("Owner").child(uid);
mRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String stallId = dataSnapshot.child("stallid").getValue().toString();
String school = dataSnapshot.child("school").getValue().toString();
xRef = mFirebaseDatabase.getReference().child("menu").child("school").child(school).child("stall").child(stallId).child("food");
options = new FirebaseRecyclerOptions.Builder<Model>().setQuery(xRef, Model.class).build();
adapter = new FirebaseRecyclerAdapter<Model, ViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ViewHolder viewHolder, int i, @NonNull Model model) {
Picasso.get().load(model.getImageurl()).into(viewHolder.i1, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
viewHolder.t1.setText(model.getName());
viewHolder.t2.setText(model.getPrice());
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row,parent,false);
return new ViewHolder(view);
}
};
GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(),2);
mRecyclerView.setLayoutManager(gridLayoutManager);
adapter.startListening();
mRecyclerView.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
我希望显示输出,但是输出为空白,并且显示E / RecyclerView:未连接适配器;跳过布局