2016-10-18 31 views
0

画像ファイルを文字列とタイトルとして文字列として投稿しようとしています。 アイブ氏は成功し、それは私のrecyclerview内の画像ファイルを表示するために取得する方法がわからないデータベースにタイトルや画像の文字列を記述することができましたが、画像とテキストをFirebaseリアルタイムデータベースに読み書きする方法

public class FireBaseReadWrite { 

private static final String TAG = "FirebaseReadWrite"; 
// Firebase instance variables 

DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference(); 
DatabaseReference listRef = mRootRef.child("post"); 



// When a user go offline this code will keep there saved data on the device 
// FirebaseDatabase.getInstance().setPersistenceEnabled(true); 

    public FireBaseReadWrite writeFirebase(String title,String imageURL){ 
     Post post = new Post(title,imageURL); 

     mRootRef.child("posts").setValue(post); 

     return null; 
    } 


public void readFirebase(){ 
    ValueEventListener postListener = new ValueEventListener() { 
     @Override 
     public void onDataChange(DataSnapshot dataSnapshot) { 
      // Get Post object and use the values to update the UI 
      Post post = dataSnapshot.getValue(Post.class); 
      Log.w(TAG, String.valueOf(post)); 

     } 

     @Override 
     public void onCancelled(DatabaseError databaseError) { 
      // Getting Post failed, log a message 
      Log.w(TAG, "loadPost:onCancelled", databaseError.toException()); 
      // ... 
     } 
    }; 

// mPostReference.addValueEventListener(postListener)。 }

}

答えて

0

私はあなたがイメージロード用ピカソライブラリhttp://square.github.io/picasso/ を使用することをお勧めします。

Picasso.with(context).load(img_url).into(imageView); 
のように(あなたのrecyclerViewに置く)あなたのImageViewの中にそれをロードする http://i.imgur.com/DvpvklR.png

String img_url = "http://i.imgur.com/DvpvklR.png"; 

使用ライブラリすなわちfirebaseデータベースから画像のURLを得たと仮定することができます

関連する問題