2017-03-22 25 views
0

首先,我從圖庫中選擇圖像,然後將其上傳到Firebase存儲,並在Book Node中存儲路徑以及有關Book的其他信息。如何通過在Firebase數據庫中使用圖像路徑來顯示圖像?

那麼如何獲取圖像並將其顯示在imageView中?

我的活動(我在做以獲得有關該書的其它信息):

ref = dataBD.getReference("books"); 
ref.addValueEventListener(new ValueEventListener() { 
    @Override 
    public void onDataChange(DataSnapshot dataSnapshot) { 

     for (DataSnapshot dataSnap : dataSnapshot.getChildren()) { 

      Book valueBook=dataSnap.getValue(Book.class); 
      String idBookDisplay=valueBook.getId_Book(); 

     if(id_user.equals(idBookDisplay)){ 

      String titreLivreToDisplay=valueBook.getNom_livre(); 
      String descLivreToDisplay=valueBook.getDesc_livre(); 
      String prixLivreToDisplay=valueBook.getPrix_livre(); 
      String timeToDisplay=valueBook.getDate_creation(); 

      Book item = new Book(); 

      item.setNom_livre(titreLivreToDisplay); 
      item.setDesc_livre(descLivreToDisplay); 
      item.setPrix_livre(prixLivreToDisplay); 
      item.setDate_creation(timeToDisplay); 

      feedItems.add(item); 


     } 

     } 


     listAdapter = new FeedListAdapter(AccueilActivity.this,feedItems); 
     listView.setAdapter(listAdapter); 
     listAdapter.notifyDataSetChanged(); 

    } 

的ImageView的佈局文件:

<ImageView 
       android:id="@+id/book_picture_display" 
       android:layout_width="@dimen/feed_item_profile_pic" 
       android:layout_height="@dimen/feed_item_profile_pic" 
       android:scaleType="fitCenter" /> 

節點書籍:

enter image description here

回答

0

首先,請存儲完整的圖像路徑,包括Firebase存儲域在像這樣的路徑gs://<yourapp>.appspot.com/images/<your_image_name>您將能夠從firebase存儲下載圖像。

使用當前可見的數據快照,這是解決方案。

感謝

+0

我做到了,現在我的圖片的路徑是這樣的:'GS://book-...com//images/sport23- 03-2017_15:22:54',但我有一個錯誤:'StorageException發生了.Object在location.Code不存在:-13010 HttpResult:404' – Amal

0

我用來解決FirebaseUI

storageRef = storageDisplayImg.getReferenceFromUrl(item.getChemin_image()‌​); // return gs://mydreambook-32321.appspot.com/images/test23-03-2017_16:46:55 


      Glide.with(convertView.getContext()) 
        .using(new FirebaseImageLoader()) 
        .load(storageRef) 
        .into(profilePic); 
      profilePic.setVisibility(View.VISIBLE); 
相關問題