I’m having trouble with my listviews items. I’m dynamically getting some images from a XML file, downloading the image and setting it.
I’m trying to primitively cache the bitmap fetched to speed up the getView process of my listviews adapter. But when trying to scroll my listview the phone seems to ‘lag’.
This is the part of my code which is responsible for the ‘lag’:
if( ni.Bitmap == null )
{
Pattern p = Pattern.compile("<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>");
Matcher m = p.matcher(ni.Description);
boolean result = m.find();
if( result )
{
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(m.group(1)).getContent());
ni.Bitmap = bitmap;
holder.theimage.setImageBitmap(ni.Bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
else
holder.theimage.setImageBitmap(ni.Bitmap);
Can I in anyway speed up this process?
Check this Url. you will get lot thing about this.
https://stackoverflow.com/search?q=lazy+loading+listview+android