我想在Recycler视图中从Firebase中获取随机数据,就像我在Firebase中有5个引用,并且在Recycler视图中检索它们一样,它们都工作正常,但是当我尝试获取随机数据时出现了问题,例如第一名是Firebase的3参考,第三名是Firebase的5参考,我尝试了很多方法,但都失败了,任何人都知道请调查一下。
这是我检索Firebase数据的主类
public class Tab3Fragment extends Fragment {
public Tab3Fragment() {
// Required empty public constructor
}
RecyclerView recyclerView;
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference reference = firebaseDatabase.getReference("Tab3IMAGES");
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_tab3, container, false);
recyclerView = (RecyclerView)v.findViewById(R.id.recyletab3);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(),2));
return v;
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<UserProfile,ViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<UserProfile, ViewHolder>
(
UserProfile.class,R.layout.row,ViewHolder.class,reference
)
{
@Override
protected void populateViewHolder(ViewHolder viewHolder, UserProfile model, int position) {
viewHolder.setDetails(getActivity(), model.getImage(), model.getText(), model.getImageInside());
}
};
recyclerView.setAdapter(firebaseRecyclerAdapter);
}
这是我的视图持有人
public void setDetails(final Context ctx, String image, final String text, final String imageInside)
{
ImageView imageView = mView.findViewById(R.id.imagerow);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(ctx, Stories.class);
i.putExtra("first", text);
i.putExtra("second", imageInside);
ctx.startActivities(new Intent[]{i});
}
});
Picasso.get().load(image).into(imageView);
}