android - How to retrieve Images from firebase in listview -


i trying retrieve images in listview using firebase list adapter.i using pojo class saving , retriving images firebase.

below pojo class: 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;   } } 

code storing images:

 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();                               }                           }                       });  

code retriving images:

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); 

how set getter in firebase list adapter fetch images.

you use json stored on firebase, saving url-images (located example on imgur) , use glide retrieving image without kind of complication, futurestud.io website e.g.:

imageview targetimageview = (imageview) findviewbyid(r.id.imageview); string interneturl = "http://i.imgur.com/dvpvklr.png";  glide     .with(context)     .load(interneturl)     .into(targetimageview); 

trust me, it's simple firebase


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -