android - I want to place background image where "image url" is not present -


i want place background image "image url" not present .

i not getting background image image url not present . why not appearing ?

please see in image 1 image url not present in json should replace "bc.jpeg" have placed in drawable folder.

but not coming why not showing ?

image not present

main activity

public class mainactivity extends activity {     // log tag     private static final string tag = mainactivity.class.getsimplename();     private static final string url = "http://qzrbzpztcd.localtunnel.me/api/v1/restaurants?per_page=10&page=1&sort_col=average_ratings";     // movies json url     //private static final string url = "http://api.androidhive.info/json/movies.json";     private progressdialog pdialog;     private list<movie> movielist = new arraylist<movie>();     private listview listview;     private customlistadapter adapter;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         listview = (listview) findviewbyid(r.id.list);         adapter = new customlistadapter(this, movielist);         listview.setadapter(adapter);         pdialog = new progressdialog(this);         // showing progress dialog before making http request         pdialog.setmessage("loading...");         pdialog.show();         // changing action bar color         getactionbar().setbackgrounddrawable(                 new colordrawable(color.parsecolor("#1b1b1b")));         // creating volley request obj         jsonarrayrequest moviereq = new jsonarrayrequest(url,                 new response.listener<jsonarray>() {                     @override                     public void onresponse(jsonarray response) {                         log.d(tag, response.tostring());                         hidepdialog();                         // parsing json                         (int = 0; < response.length(); i++) {                             try {                                 jsonobject obj = response.getjsonobject(i);                                 movie movie = new movie();                                 //movie.settitle(obj.getstring("title"));                                 movie.setname(obj.getstring("name"));                                 //movie.setthumbnailurl(obj.getstring("image"));                                 movie.setthumbnailurl(obj.getstring("image_url"));                                 movie.setaverage_ratings(obj.getstring("average_ratings"));                                 movie.setcuisine(obj.getstring("cuisine"));                                 movie.setaddress(obj.getjsonobject("address").getstring("area"));                                 //movie.setaddress(obj.getstring("address"));                                 //movie.setyear(obj.getint("releaseyear"));                                 // genre json array                                 /*jsonarray genrearry = obj.getjsonarray("genre");                                 arraylist<string> genre = new arraylist<string>();                                 (int j = 0; j < genrearry.length(); j++) {                                     genre.add((string) genrearry.get(j));                                 }                                 movie.setgenre(genre);*/                                 // adding movie movies array                                 movielist.add(movie);                             } catch (jsonexception e) {                                 e.printstacktrace();                             }                         }                          // notifying list adapter data changes                         // renders list view updated data                         adapter.notifydatasetchanged();                     }                 }, new response.errorlistener() {                     @override                     public void onerrorresponse(volleyerror error) {                         volleylog.d(tag, "error: " + error.getmessage());                         hidepdialog();                      }                 });          // adding request request queue         appcontroller.getinstance().addtorequestqueue(moviereq);     }      @override     public void ondestroy() {         super.ondestroy();         hidepdialog();     }      private void hidepdialog() {         if (pdialog != null) {             pdialog.dismiss();             pdialog = null;         }     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }  } 

list row.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:background="@drawable/list_row_selector"     android:padding="8dp" >      <!-- thumbnail image -->     <com.android.volley.toolbox.networkimageview         android:id="@+id/thumbnail"         android:layout_width="120dp"         android:layout_height="80dp"         android:layout_alignparentleft="true"         android:layout_marginright="8dp" />      <!-- restaurant name  -->     <textview         android:id="@+id/name"         android:layout_width="wrap_content"         android:layout_height="wrap_content"          android:layout_torightof="@+id/thumbnail"         android:textsize="@dimen/title"         android:textstyle="bold" />      <textview         android:id="@+id/area"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_below="@id/name"          android:layout_torightof="@+id/thumbnail"         android:textsize="@dimen/rating" />      <!-- rating -->     <textview         android:id="@+id/average_ratings"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_below="@id/area"         android:layout_torightof="@+id/thumbnail"          android:textsize="@dimen/rating" />      <textview         android:id="@+id/cuisine"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_below="@id/average_ratings"          android:layout_torightof="@+id/thumbnail"         android:textsize="@dimen/rating" />      <!-- genre -->    <!-- <textview         android:id="@+id/genre"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_below="@id/rating"         android:layout_margintop="5dp"         android:layout_torightof="@+id/thumbnail"         android:textcolor="@color/genre"         android:textsize="@dimen/genre" />--> <!--     &lt;!&ndash; release year &ndash;&gt;     <textview         android:id="@+id/releaseyear"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_alignparentright="true"         android:textcolor="@color/year"         android:textsize="@dimen/year" />-->  </relativelayout> 

customlist adapter.java

public class customlistadapter extends baseadapter {     private activity activity;     private layoutinflater inflater;     private list<movie> movieitems;     imageloader imageloader = appcontroller.getinstance().getimageloader();      public customlistadapter(activity activity, list<movie> movieitems) {         this.activity = activity;         this.movieitems = movieitems;     }      @override     public int getcount() {         return movieitems.size();     }      @override     public object getitem(int location) {         return movieitems.get(location);     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(int position, view convertview, viewgroup parent) {          if (inflater == null)             inflater = (layoutinflater) activity.getsystemservice(context.layout_inflater_service);         if (convertview == null)             convertview = inflater.inflate(r.layout.list_row, null);          if (imageloader == null)             imageloader = appcontroller.getinstance().getimageloader();         networkimageview thumbnail = (networkimageview) convertview                 .findviewbyid(r.id.thumbnail);         textview name = (textview) convertview.findviewbyid(r.id.name);         textview average_ratings = (textview) convertview.findviewbyid(r.id.average_ratings);         textview address=(textview) convertview.findviewbyid(r.id.area);         textview cuisine =(textview) convertview.findviewbyid(r.id.cuisine);         //textview genre = (textview) convertview.findviewbyid(r.id.genre);         //textview year = (textview) convertview.findviewbyid(r.id.releaseyear);          // getting movie data row         movie m = movieitems.get(position);          // thumbnail image         //thumbnail.setimageurl(m.getthumbnailurl(), imageloader);         if (m.getthumbnailurl().compareto("")!=0)             thumbnail.setimageurl(m.getthumbnailurl(), imageloader);         else{         thumbnail.setimageresource(r.drawable.bc);         }           // title         name.settext(m.getname());          // rating         average_ratings.settext("rating: " + string.valueof(m.getaverage_ratings()));         address.settext("area: " + string.valueof(m.getaddress()));         cuisine.settext("cusine: " + string.valueof(m.getcuisine()));         /*// genre         string genrestr = "";         (string str : m.getgenre()) {             genrestr += str + ", ";         }         genrestr = genrestr.length() > 0 ? genrestr.substring(0,                 genrestr.length() - 2) : genrestr;         genre.settext(genrestr);          // release year         year.settext(string.valueof(m.getyear()));*/          return convertview;     }  } 

movie.java

public class movie {     private string name, thumbnailurl;     //private int year;     private string average_ratings,area,cuisine,address; //  private arraylist<string> genre;      public movie() {     }      public movie(string name, string thumbnailurl, string average_ratings,string area,string cuisine,string address             ) {         this.name = name;         this.thumbnailurl = thumbnailurl;         //this.year = year;         this.average_ratings = average_ratings;         this.area=area;         this.cuisine=cuisine; this.address=address;         //this.genre = genre;     }      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }      public string getthumbnailurl() {         return thumbnailurl;     }      public void setthumbnailurl(string thumbnailurl) {         this.thumbnailurl = thumbnailurl;     }      /*public int getyear() {         return year;     }*/      /*public void setyear(int year) {         this.year = year;     }*/      public string getaverage_ratings() {         return average_ratings;     }      public void setaverage_ratings(string average_ratings) {         this.average_ratings = average_ratings;     }     public string getaddress() {         return address;     }      public void setaddress(string address) {         this.address = address;     }      public string getcuisine() {         return cuisine;     }      public void setcuisine(string cuisine) {         this.cuisine = cuisine;     }     /*public arraylist<string> getgenre() {         return genre;     }      public void setgenre(arraylist<string> genre) {         this.genre = genre;     } */ } 

to display placeholder while image loading, use:

thumbnail.setdefaultimageresid(r.drawable.your_placeholder);  

to display image error if image doesn`t load error, use:

thumbnail.seterrorimageresid(r.drawable.your_error); 

what use glide?

"glide fast , efficient open source media management , image loading framework android wraps media decoding, memory , disk caching, , resource pooling simple , easy use interface."

its use easy.

glide .with(context) .load(url) .placeholder(r.drawable.loading_spinner) .into(myimageview);

using this, glide handle you.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -