如何在适配器类中显示所有图像URL以及用户名,标题,uid,时间戳

时间:2018-06-20 10:19:46

标签: android firebase firebase-realtime-database

我正在尝试显示所有图像URL以及用户名,时间戳和标题,但仅显示一张图像。我正在使用recyclerview适配器。我想在适配器中显示所有带有长标题,时间戳和用户名的图像URL,如一篇帖子

这是我使用Blog类存储在Firebase数据库中的方式

 ArrayList<Uri> arrayListImageDownloadUri = new ArrayList<>();
                            final Uri downloaduri = taskSnapshot.getDownloadUrl();
                            Log.v("DOWNLOAD URI", String.valueOf(downloaduri));
                            blogimages.add(downloaduri.toString());
                            Log.v("BLOGGIMAGES", String.valueOf(blogimages));
                           // final String path=  uri.getLastPathSegment();
                            final DatabaseReference ref =  FirebaseDatabase.getInstance().getReference().child("posts/");


                            final String newPostKey = ref.push().getKey();
                            final String posttitle = desc.getText().toString();
                            final String CurrentUser = firebaseAuth.getCurrentUser().getUid();
                            userid = FirebaseDatabase.getInstance().getReference().child("Blog").child(CurrentUser).push();
                            ArrayList<String> arrayList = new ArrayList<>();
                            for(int i=0; i<blogimages.size();i++) {

                                arrayList.add( blogimages.get(i).toString());
                                Log.v("IMAGESADDING PHSE3", String.valueOf(arrayList));
                            }
                            Log.v("COCOCOCOCO", String.valueOf(arrayList));

                                n.put(String.valueOf("img"), blogimages.get(i).toString());*/
                                Blog blog = new Blog();
                                long millis = System.currentTimeMillis();
                                int timestamp = ((int) (millis/1000))* -1;
                                blog.setTitle(posttitle);
                                blog.setUrl(arrayList);
                                blog.setUid(firebaseAuth.getCurrentUser().getUid());


                            mdatabaseReference.child(CurrentUser).setValue(blog)

                                .addOnSuccessListener(new OnSuccessListener<Void>() {
                                    @Override
                                    public void onSuccess(Void aVoid) {
                                        Intent mm = new Intent(PhotoUploadActivity.this, MainActivity.class);
                                        startActivity(mm);
                                    }
                                }).addOnFailureListener(new OnFailureListener() {
                                    @Override
                                    public void onFailure(@NonNull Exception e) {
                                        Toast.makeText(PhotoUploadActivity.this, "Failed to post the blog.. Try again later", Toast.LENGTH_LONG).show();
                                    }
                                });

1 个答案:

答案 0 :(得分:0)

获取博客数据时,可以在成功侦听器中使用它:

$ go run -race racer.go
==================
WARNING: DATA RACE
Read at 0x0000005e3600 by goroutine 6:
  main.main.func1()
      /home/peter/gopath/src/racer.go:17 +0x63

Previous write at 0x0000005e3600 by main goroutine:
  main.main()
      /home/peter/gopath/src/racer.go:22 +0x7b

Goroutine 6 (running) created at:
  main.main()
      /home/peter/gopath/src/racer.go:15 +0x4f
==================
i am here 3622
i am here 43165250
i am here 86147697
^Csignal: interrupt
$

注意: ,您必须在“已更改,已删除...”子项上实现方法。