Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid remote image in listview - what to do if missing?
    text
    copied!<p>I'm working on app that reads remote XML with this structure:</p> <pre><code>&lt;items&gt; &lt;item&gt; &lt;id&gt;ID&lt;/id&gt; &lt;title&gt;TITLE&lt;/title&gt; &lt;img_url&gt;http://URL&lt;/img_url&gt; &lt;/item&gt; &lt;/items&gt; </code></pre> <p>I'm parsing this XML and feed the listview with the data from XML. When an image URL is provided I load the image from remote URL, it works fine.</p> <p>Problems are:</p> <ul> <li>how to find out that there is no image at that URL to prevent application from failure when trying to load not existing image?</li> <li>how to load some default image when no image URL is provided?</li> </ul> <p>To explain: it happened recently that there was no image at URL provided in XML, so my Android app failed to load it and it was force closed (yes, I then put it into try-catch but I'd rather show a default "no image" image instead). There can be items with no image URL and in that case I'd like to show some default "no image" image. But how to process local image file when my custom ArrayAdapter is expecting an URL for image to be downloaded?</p> <p>My app life cycle is as follows:</p> <ol> <li>start activity is a listview</li> <li>it calls GetItems method that loads the XML, parses it and fill in the custom ArrayAdapter</li> <li>in the GetView method of AA the drawable bitmap from image URL is loaded in the ImageView - so I suppose here all the problem should be fixed - check for the url, it is provided check for the loaded image, of it is loaded then show it; if no url or no image loaded, load default image...</li> </ol> <p>I know the algorithm, what I'm looking for is some (working) code example...</p> <p>Many thanks for any advice...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload