应该显示来自Firebase的图片,但是" RecyclerView:没有附加适配器;跳过布局"错误出现了

时间:2017-03-10 08:54:42

标签: android firebase-realtime-database android-recyclerview android-adapter firebase-storage

我的RecyclerView是空的,应该从数据库中填充上传的图片。我按照simplifiedcoding的说明操作,不确定是什么错误。

//recyclerview object
private RecyclerView recyclerView;

//adapter object
private RecyclerView.Adapter adapter;

//database reference
private DatabaseReference mDatabase;

//progress dialog
private ProgressDialog progressDialog;

//list to hold all the uploaded images
private List<Upload> uploads;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_show_images);



    //adding adapter to recyclerview


    progressDialog = new ProgressDialog(this);

    uploads = new ArrayList<>();

    //displaying progress dialog while fetching images
    progressDialog.setMessage("Please wait...");
    progressDialog.show();
    mDatabase = FirebaseDatabase.getInstance().getReference(Constants.DATABASE_PATH_UPLOADS);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));



    //adding an event listener to fetch values
    mDatabase.addValueEventListener(new ValueEventListener() {


        @Override
        public void onDataChange(DataSnapshot snapshot) {
            //dismissing the progress dialog
            progressDialog.dismiss();

            //iterating through all the values in database
            for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                Upload upload = postSnapshot.getValue(Upload.class);
                uploads.add(upload);
            }
            //creating adapter
            recyclerView.setAdapter(adapter);
            recyclerView.setHasFixedSize(true);


        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            progressDialog.dismiss();
        }
    });

}
}

0 个答案:

没有答案