How to show image from server into Glide in android -


i want load image server json , show imageview glide library, write below codes not show me image in imageview!!
issue use log.d , toast show image link (image link on server) , show me image link in imageview not image!!

datamodel :

public class datamodel implements serializable {      private static final long serialversionuid = 1l;     private int id;     private string title;     private string description;     private string image;     private string category;     private string date;     private string price;      public datamodel(int id, string title, string description, string category, string date, string image) {         this.id = id;         this.title = title;         this.description = description;         this.category = category;         this.date = date;         this.image = image;     }      public string getprice() {         return price;     }      public void setprice(string price) {         this.price = price;     }      public string getdate() {         return date;     }      public void setdate(string date) {         this.date = date;     }      public string getcategory() {         return category;     }      public void setcategory(string category) {         this.category = category;     }      public string getimage() {         return image;     }      public void setimage(string image) {         this.image = image;     }      public string getdescription() {         return description;     }      public void setdescription(string description) {         this.description = description;     }      public string gettitle() {         return title;     }      public void settitle(string title) {         this.title = title;     }      public int getid() {         return id;     }      public void setid(int id) {         this.id = id;     }  } 

asynctask :

public class freedatainfo {     private context mcontext;     private string serveraddress = freeserver_ip.getfreeip();      public void getfreedatainfo(context context) {         mcontext = context;         new getinfo().execute(serveraddress + "limit=10");     }      private class getinfo extends asynctask<string, void, string> {         eventbus bus = eventbus.getdefault();         private string ou_response;         private list<datamodel> infomodels = new arraylist<>();         private progressdialog dialog;          @override         protected void onpreexecute() {             //customprocessdialog.createandshow(mcontext);              dialog = new progressdialog(mcontext);             this.dialog.setmessage("شکیبا باشید...");             this.dialog.show();              infomodels.clear();         }          @override         protected string doinbackground(string... params) {             okhttpclient client = new okhttpclient();              //string url = (string) params[0];             request request = new request.builder()                     .url(serveraddress + "limit=10")                     .cachecontrol(cachecontrol.force_network)                     .build();              response response;             try {                 response = client.newcall(request).execute();                 ou_response = response.body().string();                 response.body().close();                 if (ou_response != null) {                     try {                         jsonobject postobj = new jsonobject(ou_response);                         jsonarray postsarray = postobj.optjsonarray("result");                          (int = 0; <= postsarray.length(); i++) {                             jsonobject postobject = (jsonobject) postsarray.get(i);                              int id = postobject.getint("id");                             log.d("id", string.valueof(id));                             string title = postobject.getstring("title");                             string description = postobject.getstring("description");                             string image = postobject.getstring("image");                             string category = postobject.getstring("categoryname");                             string date = postobject.getstring("publishdate");                              log.d("data", "post id: " + id);                             log.d("data", "post title: " + title);                             log.d("data", "post image: " + image);                             log.d("data", "---------------------------------");                              //use title , id per requirement                             infomodels.add(new datamodel(id, title, description, category, date, image));                         }                     } catch (jsonexception e) {                         e.printstacktrace();                         log.e("error", string.valueof(e));                     }                 }             } catch (ioexception e) {                 e.printstacktrace();                 log.e("error2", string.valueof(e));             }             return ou_response;         }          @override         protected void onpostexecute(string result) {             //customprocessdialog.dissmis();              //stop progress             if (dialog.isshowing()) {                 dialog.dismiss();             }              if (result != null) {                 bus.post(new myevent("forfragment1", infomodels));             } else {                 toast.maketext(mcontext, "empty", toast.length_short).show();             }         }     } 

adapter :

public class free_recycler_adapter extends recyclerview.adapter<free_recycler_adapter.viewholder> {     private list<datamodel> mdateset;     private context context;      // provide suitable constructor (depends on kind of dataset)     public free_recycler_adapter(context context, list<datamodel> dataset) {         this.context = context;         this.mdateset = dataset;     }      // create new views (invoked layout manager)     @override     public free_recycler_adapter.viewholder oncreateviewholder(viewgroup parent, int viewtype) {         // create new view         view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.free_card_layout, parent, false);          // create viewholder         return new viewholder(view);     }      // replace contents of view (invoked layout manager)     @override     public void onbindviewholder(viewholder viewholder, int position) {          // - data itemsdata @ position         // - replace contents of view itemsdata          viewholder.free_titletext.settext(html.fromhtml(mdateset.get(position).gettitle()));         glide.with(context)                 .load(mdateset.get(position).getimage())                 .placeholder(r.drawable.ic_download_image)                 .crossfade()                 .into(viewholder.free_avatarimage);         viewholder.free_desctext.settext(html.fromhtml(mdateset.get(position).getdescription()));         log.d("imagedata", "image : " + mdateset.get(position).getimage());      }      // return size of dataset (invoked layout manager)     @override     public int getitemcount() {         return mdateset.size();     }      public void remove(int position) {         mdateset.remove(position);         notifyitemremoved(position);     }      public void clear() {         mdateset.clear();         notifydatasetchanged();     }      public void add(list<datamodel> models) {         mdateset.addall(models);         notifydatasetchanged();     }      public void update(list<datamodel> models) {         mdateset.clear();         mdateset.addall(models);         notifydatasetchanged();     }      // inner class hold reference each item of recyclerview     public static class viewholder extends recyclerview.viewholder {          public textview free_titletext, free_desctext;         public imageview free_avatarimage;          public viewholder(view itemlayoutview) {             super(itemlayoutview);              free_titletext = (textview) itemlayoutview.findviewbyid(r.id.pdf_card_title);             free_desctext = (textview) itemlayoutview.findviewbyid(r.id.pdf_card_content);             free_avatarimage = (imageview) itemlayoutview.findviewbyid(r.id.pdf_card_image);              itemlayoutview.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     intent intent = new intent(v.getcontext(), contentpage.class);                     v.getcontext().startactivity(intent);                 }             });         }     } } 

log :

06-11 05:37:20.808 1692-1692/com.razemovafaghiat.tellfa.android d/imagedata: image : http:/razemovafaghiat.ir/uploads/download/egve.jpg 

how can fix problem , show image in imageview? <3

you have followed correct approach. problem tricky yet easy solve.

the url receive

http:/razemovafaghiat.ir/uploads/download/egve.jpg 

but should this,

http://razemovafaghiat.ir/uploads/download/egve.jpg 

glide unable understand or parse previous url. have tried , works 2nd url.

just change url receive server proper url format. if don't have control on backend server, try rectify url in client code.

if want see working once, try once,

glide.with(getcontext()).load("http://razemovafaghiat.ir/uploads/download/egve.jpg").into(mimageview); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -