Firebaseのリストアダプタを使用してリストビューでイメージを取得しようとしています.POFクラスを使用してFirebaseのイメージを保存しています。リストビューのfirebaseからイメージを取り出す方法
以下は、私のPOJOクラスです:Data.java
public class Data {
String imag;
public Data(){
}
public Data(String imag){
this.imag = imag;
}
public String getImag() {
return imag;
}
public void setImag(String imag) {
this.imag = imag;
}
}
コード画像を保存するために:
Firebase ref = new Firebase("https://imaglist.firebaseio.com");
Bitmap bm = BitmapFactory.decodeFile(imgDecodableString);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG,100,baos);
byte[] byteArray = baos.toByteArray();
encodedImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
Data d = new Data();
d.setImag(encodedImage);
ref.child("Photo").push().setValue(d, new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
if(firebaseError != null){
Toast.makeText(getApplicationContext(),firebaseError.getMessage(),Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(),"Image Saved",Toast.LENGTH_SHORT).show();
}
}
});
コード画像をretrivingため:
list = (ListView)findViewById(R.id.list);
img = (ImageView)findViewById(R.id.img);
FirebaseListAdapter<Data> ad = new FirebaseListAdapter<Data>(MainActivity.this,Data.class,R.layout.row,ref) {
@Override
protected void populateView(View view, Data data, int i) {
Data d = new Data();
byte[] dec = Base64.decode(encodedImage,Base64.DEFAULT);
Bitmap decodeByte = BitmapFactory.decodeByteArray(dec, 0, dec.length);
img.setImageBitmap(decodeByte);
}
};
list.setAdapter(ad);
firebaseにゲッターを設定する方法リストアダプターを使用してイメージを取得します。
私はあなたにお勧めします。 は今すぐこのコードを使用し、あなたのfirebaseリストアダプタ用のテンプレートとしてlistset使用します –
Base64文字列の画像を変換しているので、上記のコードでgetterメソッドを使用するとどうすればできますか? –
グライドを使ってfirebaseから画像を取り出す方法をコードで教えてください。 –