[android-developers] Lazy Loading
Quality Image Lazy Loading Strategy - http://www.ryangmattison.com/post/2011/12/15/AsynchronousImageProvider.aspx -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Lazy loading contact images to a ListView in Android
What is the easiest way of lazy loading contact images to a ListView in Android? (for SDK level =7) Is there a common approach or should I choose one of the different approaches discussed here on lazy loading web images into ListViews? I have come across the ContactPhotoLoader used inside the default Contacts application which seems ok for me. Is there a better approach to do it? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Lazy loading in HorizontalScrollView to prevent Out of Memory issue
I want to add lazy loading feature to HorizontalScrollView, It has linearlayout as a child and i am addding to linearlayout, I am interested in listening to the event when the child view is out of the visibility area, I see in linearlayout implementation it does not call either dispatchViewVisibility or onDraw on child view , why i want that because bitmap attached to the child view can be recycled and create bitmap again when child view is visible (well that is a separate part ,How can i create that bitmap very fast, I am planning to use opengl for that) but the question is how can make such custom view. I can not use gallery view because it does not solve my purpose I saw that viewgroup has feature of dispatchingViewVisibility and dispatchOnDraw but not sure how to use that with HorizontalScrollView.? All i am doing to prevent Out of Memory issue Any suggestion and help would be appreciated thanks -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Lazy Loading in custom View
Hi Kostya, I am repeatedly getting 02-28 06:16:40.267: DEBUG/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol in my Sudoku program. Also my program doesn't proceed from these statements even after 1 hour.My files are the same as given in Ed Burnette's book. My LogCat is: 03-01 02:02:53.252: DEBUG/AndroidRuntime(282): AndroidRuntime START 03-01 02:02:53.263: DEBUG/AndroidRuntime(282): CheckJNI is ON 03-01 02:02:55.381: DEBUG/AndroidRuntime(282): --- registering native functions --- 03-01 02:03:01.543: INFO/ActivityManager(69): Start proc com.android.defcontainer for service com.android.defcontainer/.DefaultContainerService: pid=289 uid=10010 gids={1015, 2001} 03-01 02:03:03.863: DEBUG/dalvikvm(289): GC_EXPLICIT freed 768 objects / 55584 bytes in 298ms 03-01 02:03:04.762: DEBUG/PackageParser(69): Scanning package: /data/ app/vmdl67559.tmp 03-01 02:03:05.693: INFO/PackageManager(69): Removing non-system package:org.example.sudoku 03-01 02:03:05.743: INFO/ActivityManager(69): Force stopping package org.example.sudoku uid=10037 03-01 02:03:06.403: DEBUG/PackageManager(69): Scanning package org.example.sudoku 03-01 02:03:06.461: INFO/PackageManager(69): Package org.example.sudoku codePath changed from /data/app/ org.example.sudoku-2.apk to /data/app/org.example.sudoku-1.apk; Retaining data and using new 03-01 02:03:06.512: INFO/PackageManager(69): /data/app/ org.example.sudoku-1.apk changed; unpacking 03-01 02:03:06.681: DEBUG/installd(35): DexInv: --- BEGIN '/data/app/ org.example.sudoku-1.apk' --- 03-01 02:03:07.793: DEBUG/dalvikvm(298): DexOpt: load 259ms, verify 53ms, opt 12ms 03-01 02:03:07.881: DEBUG/installd(35): DexInv: --- END '/data/app/ org.example.sudoku-1.apk' (success) --- 03-01 02:03:07.923: WARN/PackageManager(69): Code path for pkg : org.example.sudoku changing from /data/app/org.example.sudoku-2.apk to /data/app/org.example.sudoku-1.apk 03-01 02:03:07.932: INFO/ActivityManager(69): Force stopping package org.example.sudoku uid=10037 03-01 02:03:07.993: WARN/PackageManager(69): Resource path for pkg : org.example.sudoku changing from /data/app/org.example.sudoku-2.apk to /data/app/org.example.sudoku-1.apk 03-01 02:03:08.082: DEBUG/PackageManager(69): Activities: org.example.sudoku.Sudoku 03-01 02:03:08.771: INFO/installd(35): move /data/dalvik-cache/ data@a...@org.example.sudoku-1.apk@classes.dex - /data/dalvik-cache/ data@a...@org.example.sudoku-1.apk@classes.dex 03-01 02:03:08.822: DEBUG/PackageManager(69): New package installed in /data/app/org.example.sudoku-1.apk 03-01 02:03:09.872: INFO/ActivityManager(69): Force stopping package org.example.sudoku uid=10037 03-01 02:03:10.811: DEBUG/dalvikvm(126): GC_EXPLICIT freed 177 objects / 7544 bytes in 327ms 03-01 02:03:11.712: INFO/ActivityManager(69): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=300 uid=10028 gids={} 03-01 02:03:13.012: WARN/RecognitionManagerService(69): no available voice recognition services found 03-01 02:03:14.872: DEBUG/dalvikvm(165): GC_EXPLICIT freed 4204 objects / 254440 bytes in 4142ms 03-01 02:03:14.913: DEBUG/dalvikvm(69): GC_FOR_MALLOC freed 8175 objects / 526176 bytes in 593ms 03-01 02:03:15.663: DEBUG/dalvikvm(69): GC_EXPLICIT freed 340 objects / 19648 bytes in 591ms 03-01 02:03:16.802: INFO/installd(35): unlink /data/dalvik-cache/ data@a...@org.example.sudoku-2.apk@classes.dex 03-01 02:03:17.222: INFO/ActivityThread(300): Publishing provider com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider 03-01 02:03:17.691: DEBUG/AndroidRuntime(282): Shutting down VM 03-01 02:03:17.703: INFO/AndroidRuntime(282): NOTE: attach of thread 'Binder Thread #4' failed 03-01 02:03:17.783: DEBUG/dalvikvm(282): Debugger has detached; object registry had 1 entries 03-01 02:03:20.482: DEBUG/AndroidRuntime(310): AndroidRuntime START 03-01 02:03:20.482: DEBUG/AndroidRuntime(310): CheckJNI is ON 03-01 02:03:22.212: DEBUG/AndroidRuntime(310): --- registering native functions --- 03-01 02:03:27.391: INFO/ActivityManager(69): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x1000 cmp=org.example.sudoku/.Sudoku } 03-01 02:03:27.682: DEBUG/AndroidRuntime(310): Shutting down VM 03-01 02:03:27.801: DEBUG/dalvikvm(310): Debugger has detached; object registry had 1 entries 03-01 02:03:27.833: INFO/AndroidRuntime(310): NOTE: attach of thread 'Binder Thread #3' failed 03-01 02:03:28.643: INFO/ActivityManager(69): Start proc org.example.sudoku for activity org.example.sudoku/.Sudoku: pid=317 uid=10037 gids={} 03-01 02:03:32.933: INFO/ActivityManager(69): Displayed activity org.example.sudoku/.Sudoku: 4761 ms (total 271945 ms) 03-01 02:03:33.001: INFO/ActivityManager(69): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 272056 ms (total 272056 ms) 03-01 02:03:38.872: DEBUG/dalvikvm(126): GC_EXPLICIT freed 676 objects / 38544 bytes in 683ms
Re: [android-developers] Lazy Loading in custom View
Those messages are coming from another process, not from your application - note the process ID, 69. SntpClient is trying to set your phone's time and failing. This in itself shouldn't cause any problems (but you could disable Settings - Date Time - Automatic). Still this makes me wonder if your phone has a working connection to the Internet. Verify by using a browser or any other network-related application (such as Gmail on the phone). Assuming your network connection is working - there probably isn't anything else to do but roll up your sleeves, launch Eclipse debugger, and figure out what's going on. -- Kostya 01.03.2011 23:37, nov пишет: Hi Kostya, I am repeatedly getting 02-28 06:16:40.267: DEBUG/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol in my Sudoku program. Also my program doesn't proceed from these statements even after 1 hour.My files are the same as given in Ed Burnette's book. My LogCat is: 03-01 02:02:53.252: DEBUG/AndroidRuntime(282): AndroidRuntime START 03-01 02:02:53.263: DEBUG/AndroidRuntime(282): CheckJNI is ON 03-01 02:02:55.381: DEBUG/AndroidRuntime(282): --- registering native functions --- 03-01 02:03:01.543: INFO/ActivityManager(69): Start proc com.android.defcontainer for service com.android.defcontainer/.DefaultContainerService: pid=289 uid=10010 gids={1015, 2001} 03-01 02:03:03.863: DEBUG/dalvikvm(289): GC_EXPLICIT freed 768 objects / 55584 bytes in 298ms 03-01 02:03:04.762: DEBUG/PackageParser(69): Scanning package: /data/ app/vmdl67559.tmp 03-01 02:03:05.693: INFO/PackageManager(69): Removing non-system package:org.example.sudoku 03-01 02:03:05.743: INFO/ActivityManager(69): Force stopping package org.example.sudoku uid=10037 03-01 02:03:06.403: DEBUG/PackageManager(69): Scanning package org.example.sudoku 03-01 02:03:06.461: INFO/PackageManager(69): Package org.example.sudoku codePath changed from /data/app/ org.example.sudoku-2.apk to /data/app/org.example.sudoku-1.apk; Retaining data and using new 03-01 02:03:06.512: INFO/PackageManager(69): /data/app/ org.example.sudoku-1.apk changed; unpacking 03-01 02:03:06.681: DEBUG/installd(35): DexInv: --- BEGIN '/data/app/ org.example.sudoku-1.apk' --- 03-01 02:03:07.793: DEBUG/dalvikvm(298): DexOpt: load 259ms, verify 53ms, opt 12ms 03-01 02:03:07.881: DEBUG/installd(35): DexInv: --- END '/data/app/ org.example.sudoku-1.apk' (success) --- 03-01 02:03:07.923: WARN/PackageManager(69): Code path for pkg : org.example.sudoku changing from /data/app/org.example.sudoku-2.apk to /data/app/org.example.sudoku-1.apk 03-01 02:03:07.932: INFO/ActivityManager(69): Force stopping package org.example.sudoku uid=10037 03-01 02:03:07.993: WARN/PackageManager(69): Resource path for pkg : org.example.sudoku changing from /data/app/org.example.sudoku-2.apk to /data/app/org.example.sudoku-1.apk 03-01 02:03:08.082: DEBUG/PackageManager(69): Activities: org.example.sudoku.Sudoku 03-01 02:03:08.771: INFO/installd(35): move /data/dalvik-cache/ data@a...@org.example.sudoku-1.apk@classes.dex - /data/dalvik-cache/ data@a...@org.example.sudoku-1.apk@classes.dex 03-01 02:03:08.822: DEBUG/PackageManager(69): New package installed in /data/app/org.example.sudoku-1.apk 03-01 02:03:09.872: INFO/ActivityManager(69): Force stopping package org.example.sudoku uid=10037 03-01 02:03:10.811: DEBUG/dalvikvm(126): GC_EXPLICIT freed 177 objects / 7544 bytes in 327ms 03-01 02:03:11.712: INFO/ActivityManager(69): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=300 uid=10028 gids={} 03-01 02:03:13.012: WARN/RecognitionManagerService(69): no available voice recognition services found 03-01 02:03:14.872: DEBUG/dalvikvm(165): GC_EXPLICIT freed 4204 objects / 254440 bytes in 4142ms 03-01 02:03:14.913: DEBUG/dalvikvm(69): GC_FOR_MALLOC freed 8175 objects / 526176 bytes in 593ms 03-01 02:03:15.663: DEBUG/dalvikvm(69): GC_EXPLICIT freed 340 objects / 19648 bytes in 591ms 03-01 02:03:16.802: INFO/installd(35): unlink /data/dalvik-cache/ data@a...@org.example.sudoku-2.apk@classes.dex 03-01 02:03:17.222: INFO/ActivityThread(300): Publishing provider com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider 03-01 02:03:17.691: DEBUG/AndroidRuntime(282): Shutting down VM 03-01 02:03:17.703: INFO/AndroidRuntime(282): NOTE: attach of thread 'Binder Thread #4' failed 03-01 02:03:17.783: DEBUG/dalvikvm(282): Debugger has detached; object registry had 1 entries 03-01 02:03:20.482: DEBUG/AndroidRuntime(310): AndroidRuntime START 03-01 02:03:20.482: DEBUG/AndroidRuntime(310): CheckJNI is ON 03-01 02:03:22.212: DEBUG/AndroidRuntime(310): --- registering native functions --- 03-01 02:03:27.391: INFO/ActivityManager(69): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x1000 cmp=org.example.sudoku/.Sudoku } 03-01 02:03:27.682: DEBUG/AndroidRuntime(310): Shutting down VM 03-01 02:03:27.801:
Re: [android-developers] Lazy Loading in custom View
On Tue, Mar 1, 2011 at 1:45 AM, Abhishek Talwar r.o.b.i.n.abhis...@gmail.com wrote: Any help will be appreciated It will be very difficult to help you with such generic, limited information. Post a screenshot of the problem, clarify what the issue is, and show some relevant code. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Lazy Loading in custom View
Sorry couldnt manage to get the screenshot some problem in my sdk i guess. Though i can share the code of my list item package com.hungama.myplay.utils; import java.io.IOException; import java.net.URL; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.hungama.myplay.activity.R; import com.hungama.myplay.model.Album; import com.hungama.myplay.model.Category; import com.hungama.myplay.model.DownloadPlan; import com.hungama.myplay.model.SearchElement; import com.hungama.myplay.model.Track; import com.hungama.myplay.model.VideoElement; public class ListItemView extends LinearLayout { private Activity activity; private Track track; private Album album; private Category category; private int resId; private ImageView iv_thumb; private VideoElement video; private int bgColor = -1; private SearchElement searchElement; private byte searchType; private boolean isPlaylistItem; private DownloadPlan plan; public ListItemView(Activity context, AttributeSet attrs) { super(context, attrs); activity = context; } public ListItemView(Activity context, int resId, Track track) { super(context); activity = context; this.track = track; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity context, int resId, Track track, boolean isPlaylistItem) { super(context); activity = context; this.track = track; this.resId = resId; this.isPlaylistItem = isPlaylistItem; addView(getListElementView()); } public ListItemView(Activity context, int resId, SearchElement searchElement, byte searchType) { super(context); this.searchType = searchType; activity = context; this.searchElement = searchElement; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity context, int resId, Album album) { super(context); activity = context; this.album = album; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity context, int resId, VideoElement video) { super(context); activity = context; this.video = video; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity context, int resId, DownloadPlan plan) { super(context); activity = context; this.plan = plan; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity activity2, int listElementView, int grey, Category category2) { super(activity2); activity = activity2; this.category = category2; this.resId = listElementView; bgColor = grey; addView(getListElementView()); } private View getListElementView() { LayoutInflater inflater = activity.getLayoutInflater(); View ConvertView = inflater.inflate(resId, null); LinearLayout linearLayout = (LinearLayout) ConvertView .findViewById(R.id.l_list_element_super_view); if (plan == null) { iv_thumb = (ImageView) ConvertView.findViewById(R.id.iv_thumbnail); ImageButton imageButton = (ImageButton) ConvertView .findViewById(R.id.imb_download); if (!isPlaylistItem) { FetchImage fetchImage = new FetchImage(); fetchImage.execute(); } else { iv_thumb.setImageResource(R.drawable.music); imageButton.setVisibility(View.GONE); } TextView tv_title = (TextView) ConvertView .findViewById(R.id.tv_list_element_title); TextView tvSecondLine = (TextView) ConvertView .findViewById(R.id.tv_list_element_album); if (this.track != null) { TextView tv_albumName = (TextView) ConvertView .findViewById(R.id.tv_list_element_album); tv_albumName.setText(track.getAlbum()); if (track.getTitle() != null) { tv_title.setText(track.getTitle()); } if (track.getAlbum() != null) { tvSecondLine.setText(track.getAlbum()); } } else if (this.album != null) { imageButton.setVisibility(View.GONE); if (album.getAlbumName() != null) { tv_title.setText(album.getAlbumName()); }
Re: [android-developers] Lazy Loading in custom View
Robin, This blog post describes something pretty close to what I think you are trying to do: http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html -- Kostya 01.03.2011 21:34, Robin Talwar ?: Sorry couldnt manage to get the screenshot some problem in my sdk i guess. Though i can share the code of my list item package com.hungama.myplay.utils; import java.io.IOException; import java.net.URL; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.hungama.myplay.activity.R; import com.hungama.myplay.model.Album; import com.hungama.myplay.model.Category; import com.hungama.myplay.model.DownloadPlan; import com.hungama.myplay.model.SearchElement; import com.hungama.myplay.model.Track; import com.hungama.myplay.model.VideoElement; public class ListItemView extends LinearLayout { private Activity activity; private Track track; private Album album; private Category category; private int resId; private ImageView iv_thumb; private VideoElement video; private int bgColor = -1; private SearchElement searchElement; private byte searchType; private boolean isPlaylistItem; private DownloadPlan plan; public ListItemView(Activity context, AttributeSet attrs) { super(context, attrs); activity = context; } public ListItemView(Activity context, int resId, Track track) { super(context); activity = context; this.track = track; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity context, int resId, Track track, boolean isPlaylistItem) { super(context); activity = context; this.track = track; this.resId = resId; this.isPlaylistItem = isPlaylistItem; addView(getListElementView()); } public ListItemView(Activity context, int resId, SearchElement searchElement, byte searchType) { super(context); this.searchType = searchType; activity = context; this.searchElement = searchElement; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity context, int resId, Album album) { super(context); activity = context; this.album = album; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity context, int resId, VideoElement video) { super(context); activity = context; this.video = video; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity context, int resId, DownloadPlan plan) { super(context); activity = context; this.plan = plan; this.resId = resId; addView(getListElementView()); } public ListItemView(Activity activity2, int listElementView, int grey, Category category2) { super(activity2); activity = activity2; this.category = category2; this.resId = listElementView; bgColor = grey; addView(getListElementView()); } private View getListElementView() { LayoutInflater inflater = activity.getLayoutInflater(); View ConvertView = inflater.inflate(resId, null); LinearLayout linearLayout = (LinearLayout) ConvertView .findViewById(R.id.l_list_element_super_view); if (plan == null) { iv_thumb = (ImageView) ConvertView.findViewById(R.id.iv_thumbnail); ImageButton imageButton = (ImageButton) ConvertView .findViewById(R.id.imb_download); if (!isPlaylistItem) { FetchImage fetchImage = new FetchImage(); fetchImage.execute(); } else { iv_thumb.setImageResource(R.drawable.music); imageButton.setVisibility(View.GONE); } TextView tv_title = (TextView) ConvertView .findViewById(R.id.tv_list_element_title); TextView tvSecondLine = (TextView) ConvertView .findViewById(R.id.tv_list_element_album); if (this.track != null) { TextView tv_albumName = (TextView) ConvertView .findViewById(R.id.tv_list_element_album); tv_albumName.setText(track.getAlbum()); if (track.getTitle() != null) { tv_title.setText(track.getTitle()); } if (track.getAlbum() != null) { tvSecondLine.setText(track.getAlbum()); }
[android-developers] Lazy Loading in custom View
Hey guys I am making a custom view extending the linearlayout and it being added to a linear layout in list view on run time. The custom view has image and text both which are coming from net. The text loads up but some of the images do not and it it is not even fixed which image position is not loaded, it is always different. But i want to show all the images, i know this can be done by lazy loading but i can not find a way to do that for my custom view. Any help will be appreciated -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Lazy Loading of images in the list view
Hi, I was trying to implement the lazy loading of images in the list view. For implementing this i was referring to post by Tom van Zummeren. (http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android- part-2/), but my images keep on changing in the list. Please can anyone let me know if they were able to get this working properly without having the images drawn again and again or let me know if I have missed on anything or doing something wrong. Thanks, Prajakta -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe, reply using remove me as the subject.
Re: [android-developers] Lazy Loading of images in the list view
Forgot to paste my code:- class IconicAdapter extends ArrayAdapter { Activity context; Context context2; HashMapString,String ret = new HashMapString,String(); AsyncLoader async;// = new AsyncLoader(); private ListView listView; HashMapString,Bitmap bit = new HashMapString,Bitmap(); IconicAdapter(Activity context) { super(context, R.layout.exclusive, items); this.context=context; async = new AsyncLoader(); } public View getView(final int position, View convertView, ViewGroup parent) { View row_inflated = View.inflate(context, R.layout.exclusive,null); wrapper = new ViewWrapper(row_inflated); row_inflated.setTag(wrapper); wrapper.getSongName().setText(items[position]); wrapper.getSingerName().setText(singer_name[position]); final ImageView imgview = wrapper.getIcon(); imgview.setTag(myRemoteImages[position]); Bitmap cachedImage = async.loadDrawable(myRemoteImages[position], new ImageCallback() { public void imageLoaded(Bitmap imageBitmap, String imageUrl) { imgview.setImageBitmap(imageBitmap); notifyDataSetChanged(); } }); if(cachedImage!=null) imgview.setImageBitmap(cachedImage); return(row_inflated); } } == AsynLoader is as below:- public class AsyncLoader{ HashMapString,Bitmap bit = new HashMapString,Bitmap(); private HashMapString, SoftReferenceBitmap imageCache; private HashMapString, SoftReferenceBitmap drawableMap; public AsyncLoader() { drawableMap = new HashMapString, SoftReferenceBitmap(); imageCache = new HashMapString, SoftReferenceBitmap(); } public Bitmap loadDrawable(final String imageUrl, final ImageCallback imageCallback) { if (drawableMap.containsKey(imageUrl)) { SoftReferenceBitmap softReference = imageCache.get(imageUrl); Bitmap drawable = softReference.get(); if (drawable != null) { return drawable; } } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageCallback.imageLoaded((Bitmap) message.obj, imageUrl); } }; new Thread() { @Override public void run() { Bitmap bitMap = loadImageFromUrl(imageUrl); imageCache.put(imageUrl, new SoftReferenceBitmap(bitMap)); Message message = handler.obtainMessage(0, bitMap); handler.sendMessage(message); } }.start(); return null; } public static Bitmap loadImageFromUrl(String url){ URL aURL; Bitmap bitmap=null;//=this.bm; try { aURL = new URL(url); URLConnection conn; conn = aURL.openConnection(); conn.connect(); InputStream is= conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bitmap = BitmapFactory.decodeStream(bis); // bitMap.put(p,bm); bis.close(); is.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return bitmap; } public interface ImageCallback { public void imageLoaded(Bitmap imageBitmap, String imageUrl); } } Thanks, Prajakta On Sat, Apr 10, 2010 at 10:21 AM, praj prajakt...@gmail.com wrote: Hi, I was trying to implement the lazy loading of images in the list view. For implementing this i was referring to post by Tom van Zummeren. (http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android- part-2/), but my images keep on changing in the list. Please can anyone let me know if they were able to get this working properly without having the images drawn again and again or let me know if I have missed on anything or doing something wrong. Thanks, Prajakta -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe, reply using remove me as the subject. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Lazy Loading of images in the list view
I was able to resolve the issue, just made simple tweaks like removing the drawableMap we just need the imageCache. On Sat, Apr 10, 2010 at 10:51 AM, Prajakta Shitole prajakt...@gmail.comwrote: Forgot to paste my code:- class IconicAdapter extends ArrayAdapter { Activity context; Context context2; HashMapString,String ret = new HashMapString,String(); AsyncLoader async;// = new AsyncLoader(); private ListView listView; HashMapString,Bitmap bit = new HashMapString,Bitmap(); IconicAdapter(Activity context) { super(context, R.layout.exclusive, items); this.context=context; async = new AsyncLoader(); } public View getView(final int position, View convertView, ViewGroup parent) { View row_inflated = View.inflate(context, R.layout.exclusive,null); wrapper = new ViewWrapper(row_inflated); row_inflated.setTag(wrapper); wrapper.getSongName().setText(items[position]); wrapper.getSingerName().setText(singer_name[position]); final ImageView imgview = wrapper.getIcon(); imgview.setTag(myRemoteImages[position]); Bitmap cachedImage = async.loadDrawable(myRemoteImages[position], new ImageCallback() { public void imageLoaded(Bitmap imageBitmap, String imageUrl) { imgview.setImageBitmap(imageBitmap); notifyDataSetChanged(); } }); if(cachedImage!=null) imgview.setImageBitmap(cachedImage); return(row_inflated); } } == AsynLoader is as below:- public class AsyncLoader{ HashMapString,Bitmap bit = new HashMapString,Bitmap(); private HashMapString, SoftReferenceBitmap imageCache; private HashMapString, SoftReferenceBitmap drawableMap; public AsyncLoader() { drawableMap = new HashMapString, SoftReferenceBitmap(); imageCache = new HashMapString, SoftReferenceBitmap(); } public Bitmap loadDrawable(final String imageUrl, final ImageCallback imageCallback) { if (drawableMap.containsKey(imageUrl)) { SoftReferenceBitmap softReference = imageCache.get(imageUrl); Bitmap drawable = softReference.get(); if (drawable != null) { return drawable; } } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageCallback.imageLoaded((Bitmap) message.obj, imageUrl); } }; new Thread() { @Override public void run() { Bitmap bitMap = loadImageFromUrl(imageUrl); imageCache.put(imageUrl, new SoftReferenceBitmap(bitMap)); Message message = handler.obtainMessage(0, bitMap); handler.sendMessage(message); } }.start(); return null; } public static Bitmap loadImageFromUrl(String url){ URL aURL; Bitmap bitmap=null;//=this.bm; try { aURL = new URL(url); URLConnection conn; conn = aURL.openConnection(); conn.connect(); InputStream is= conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bitmap = BitmapFactory.decodeStream(bis); // bitMap.put(p,bm); bis.close(); is.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return bitmap; } public interface ImageCallback { public void imageLoaded(Bitmap imageBitmap, String imageUrl); } } Thanks, Prajakta On Sat, Apr 10, 2010 at 10:21 AM, praj prajakt...@gmail.com wrote: Hi, I was trying to implement the lazy loading of images in the list view. For implementing this i was referring to post by Tom van Zummeren. (http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android- part-2/http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android-part-2/), but my images keep on changing in the list. Please can anyone let me know if they were able to get this working properly without having the images drawn again and again or let me know if I have missed on anything or doing something wrong. Thanks, Prajakta -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe, reply using remove me as the subject. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Lazy Loading of images in the list view
I think this is a recurring topic. Here is something I posted on it previously. I was looking for a recommended or consensus approach. Romain mentioned that his technique takes into consideration things like whether the list is scrolling or not. Here are 4 references that I have found for lazy-loading images into a listview in Android. The idea is to display a placeholder image, get the actual image in the background, update the ImageView in the list when the image is available. I've tried to do this in the simplest way possible using an AsyncTask in an Adapter. The outline of that approach is below. Is it flawed? Is there an agreed approach to handling this common task? Thanks, Carmen http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android-part-2/ Tom van Zummeren http://evancharlton.com/thoughts/lazy-loading-images-in-a-listview/ Evan Charlton http://code.google.com/p/shelves/ from Romain Guy http://github.com/commonsguy/cwac-thumbnail from Mark Murphy Approach using AsyncTask within an Adapter Somewhere in the Adapter. Add info about the URL for the image to fetch to the ImageView. Execute an AsyncTask to get the image in the background and load the ImageView. AsyncTask uses the tag to fetch the image. It uses the tag to find the correct view within the ListView. ImageView imageViewByTag = (ImageView) myListView.findViewWithTag( tag); ImageView is updated. Somewhere in the Adapter: myImageView.setTag(http://someimage.jpg;); // try { new GetImage().execute(myImageView); } catch(RejectedExecutionException e) { } // Asynctask private class GetImageInBackground extends AsyncTaskImageView , ImageView , Long { Drawable drawable; String tag; @Override protected void onProgressUpdate (ImageView... params){ if (drawable!=null){ ImageView imageViewByTag = (ImageView) myListView.findViewWithTag(tag); // find the ImageView if (imageViewByTag != null) { imageViewByTag.setImageDrawable(drawable); //update it } } } @Override protected Long doInBackground(ImageView... params) { tag = (String) params[0].getTag(); // get the tag from the ImageView if (tag==null){ drawable = getPlaceholder(); // get a default drawable }else{ bm =getDrawablefromURL(String (tag); // a method to get drawable from a URL } publishProgress(params[0]); return null; } } On Sat, Apr 10, 2010 at 3:10 PM, Prajakta Shitole prajakt...@gmail.comwrote: I was able to resolve the issue, just made simple tweaks like removing the drawableMap we just need the imageCache. On Sat, Apr 10, 2010 at 10:51 AM, Prajakta Shitole prajakt...@gmail.comwrote: Forgot to paste my code:- class IconicAdapter extends ArrayAdapter { Activity context; Context context2; HashMapString,String ret = new HashMapString,String(); AsyncLoader async;// = new AsyncLoader(); private ListView listView; HashMapString,Bitmap bit = new HashMapString,Bitmap(); IconicAdapter(Activity context) { super(context, R.layout.exclusive, items); this.context=context; async = new AsyncLoader(); } public View getView(final int position, View convertView, ViewGroup parent) { View row_inflated = View.inflate(context, R.layout.exclusive,null); wrapper = new ViewWrapper(row_inflated); row_inflated.setTag(wrapper); wrapper.getSongName().setText(items[position]); wrapper.getSingerName().setText(singer_name[position]); final ImageView imgview = wrapper.getIcon(); imgview.setTag(myRemoteImages[position]); Bitmap cachedImage = async.loadDrawable(myRemoteImages[position], new ImageCallback() { public void imageLoaded(Bitmap imageBitmap, String imageUrl) { imgview.setImageBitmap(imageBitmap); notifyDataSetChanged(); } }); if(cachedImage!=null) imgview.setImageBitmap(cachedImage); return(row_inflated); } } == AsynLoader is as below:- public class AsyncLoader{ HashMapString,Bitmap bit = new HashMapString,Bitmap(); private HashMapString, SoftReferenceBitmap imageCache; private HashMapString, SoftReferenceBitmap drawableMap; public AsyncLoader() { drawableMap = new HashMapString, SoftReferenceBitmap(); imageCache = new HashMapString, SoftReferenceBitmap(); } public Bitmap loadDrawable(final String imageUrl, final ImageCallback imageCallback) { if (drawableMap.containsKey(imageUrl)) { SoftReferenceBitmap softReference = imageCache.get(imageUrl); Bitmap drawable = softReference.get(); if (drawable != null) { return drawable; } } final Handler handler = new Handler() { @Override public void
Re: [android-developers] Lazy Loading of images in the list view
Hi Carmen, It was because of your post that I could implement the above code. I found the links from your post itself. Thanks for the links and procedure. Thanks, Prajakta On Sat, Apr 10, 2010 at 2:52 PM, Carmen Delessio carmendeles...@gmail.comwrote: I think this is a recurring topic. Here is something I posted on it previously. I was looking for a recommended or consensus approach. Romain mentioned that his technique takes into consideration things like whether the list is scrolling or not. Here are 4 references that I have found for lazy-loading images into a listview in Android. The idea is to display a placeholder image, get the actual image in the background, update the ImageView in the list when the image is available. I've tried to do this in the simplest way possible using an AsyncTask in an Adapter. The outline of that approach is below. Is it flawed? Is there an agreed approach to handling this common task? Thanks, Carmen http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android-part-2/ Tom van Zummeren http://evancharlton.com/thoughts/lazy-loading-images-in-a-listview/ Evan Charlton http://code.google.com/p/shelves/ from Romain Guy http://github.com/commonsguy/cwac-thumbnail from Mark Murphy Approach using AsyncTask within an Adapter Somewhere in the Adapter. Add info about the URL for the image to fetch to the ImageView. Execute an AsyncTask to get the image in the background and load the ImageView. AsyncTask uses the tag to fetch the image. It uses the tag to find the correct view within the ListView. ImageView imageViewByTag = (ImageView) myListView.findViewWithTag( tag); ImageView is updated. Somewhere in the Adapter: myImageView.setTag(http://someimage.jpg;); // try { new GetImage().execute(myImageView); } catch(RejectedExecutionException e) { } // Asynctask private class GetImageInBackground extends AsyncTaskImageView , ImageView , Long { Drawable drawable; String tag; @Override protected void onProgressUpdate (ImageView... params){ if (drawable!=null){ ImageView imageViewByTag = (ImageView) myListView.findViewWithTag(tag); // find the ImageView if (imageViewByTag != null) { imageViewByTag.setImageDrawable(drawable); //update it } } } @Override protected Long doInBackground(ImageView... params) { tag = (String) params[0].getTag(); // get the tag from the ImageView if (tag==null){ drawable = getPlaceholder(); // get a default drawable }else{ bm =getDrawablefromURL(String (tag); // a method to get drawable from a URL } publishProgress(params[0]); return null; } } On Sat, Apr 10, 2010 at 3:10 PM, Prajakta Shitole prajakt...@gmail.comwrote: I was able to resolve the issue, just made simple tweaks like removing the drawableMap we just need the imageCache. On Sat, Apr 10, 2010 at 10:51 AM, Prajakta Shitole prajakt...@gmail.comwrote: Forgot to paste my code:- class IconicAdapter extends ArrayAdapter { Activity context; Context context2; HashMapString,String ret = new HashMapString,String(); AsyncLoader async;// = new AsyncLoader(); private ListView listView; HashMapString,Bitmap bit = new HashMapString,Bitmap(); IconicAdapter(Activity context) { super(context, R.layout.exclusive, items); this.context=context; async = new AsyncLoader(); } public View getView(final int position, View convertView, ViewGroup parent) { View row_inflated = View.inflate(context, R.layout.exclusive,null); wrapper = new ViewWrapper(row_inflated); row_inflated.setTag(wrapper); wrapper.getSongName().setText(items[position]); wrapper.getSingerName().setText(singer_name[position]); final ImageView imgview = wrapper.getIcon(); imgview.setTag(myRemoteImages[position]); Bitmap cachedImage = async.loadDrawable(myRemoteImages[position], new ImageCallback() { public void imageLoaded(Bitmap imageBitmap, String imageUrl) { imgview.setImageBitmap(imageBitmap); notifyDataSetChanged(); } }); if(cachedImage!=null) imgview.setImageBitmap(cachedImage); return(row_inflated); } } == AsynLoader is as below:- public class AsyncLoader{ HashMapString,Bitmap bit = new HashMapString,Bitmap(); private HashMapString, SoftReferenceBitmap imageCache; private HashMapString, SoftReferenceBitmap drawableMap; public AsyncLoader() { drawableMap = new HashMapString, SoftReferenceBitmap(); imageCache = new HashMapString, SoftReferenceBitmap(); } public Bitmap loadDrawable(final String imageUrl, final ImageCallback imageCallback) { if
Re: [android-developers] Lazy Loading of images in the list view
I am currently trying to display a spinning progress bar till my images load in the progress bar, My progress bars are visible and when the images appear only the first row of my listview is displayed properly - as in the progress bar is dismissed and the image appears however for the rest of the rows in the list view I see both the progress bar and the images. How can I update my listview. I have used notifyDataSetChanged in my getView but still the effect is applied only to the first row and not to the rest of the rows. Can anyone let me know if I am missing on anything. Thanks, Prajakta On Sat, Apr 10, 2010 at 3:18 PM, Prajakta Shitole prajakt...@gmail.comwrote: Hi Carmen, It was because of your post that I could implement the above code. I found the links from your post itself. Thanks for the links and procedure. Thanks, Prajakta On Sat, Apr 10, 2010 at 2:52 PM, Carmen Delessio carmendeles...@gmail.com wrote: I think this is a recurring topic. Here is something I posted on it previously. I was looking for a recommended or consensus approach. Romain mentioned that his technique takes into consideration things like whether the list is scrolling or not. Here are 4 references that I have found for lazy-loading images into a listview in Android. The idea is to display a placeholder image, get the actual image in the background, update the ImageView in the list when the image is available. I've tried to do this in the simplest way possible using an AsyncTask in an Adapter. The outline of that approach is below. Is it flawed? Is there an agreed approach to handling this common task? Thanks, Carmen http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android-part-2/ Tom van Zummeren http://evancharlton.com/thoughts/lazy-loading-images-in-a-listview/ Evan Charlton http://code.google.com/p/shelves/ from Romain Guy http://github.com/commonsguy/cwac-thumbnail from Mark Murphy Approach using AsyncTask within an Adapter Somewhere in the Adapter. Add info about the URL for the image to fetch to the ImageView. Execute an AsyncTask to get the image in the background and load the ImageView. AsyncTask uses the tag to fetch the image. It uses the tag to find the correct view within the ListView. ImageView imageViewByTag = (ImageView) myListView.findViewWithTag( tag); ImageView is updated. Somewhere in the Adapter: myImageView.setTag(http://someimage.jpg;); // try { new GetImage().execute(myImageView); } catch(RejectedExecutionException e) { } // Asynctask private class GetImageInBackground extends AsyncTaskImageView , ImageView , Long { Drawable drawable; String tag; @Override protected void onProgressUpdate (ImageView... params){ if (drawable!=null){ ImageView imageViewByTag = (ImageView) myListView.findViewWithTag(tag); // find the ImageView if (imageViewByTag != null) { imageViewByTag.setImageDrawable(drawable); //update it } } } @Override protected Long doInBackground(ImageView... params) { tag = (String) params[0].getTag(); // get the tag from the ImageView if (tag==null){ drawable = getPlaceholder(); // get a default drawable }else{ bm =getDrawablefromURL(String (tag); // a method to get drawable from a URL } publishProgress(params[0]); return null; } } On Sat, Apr 10, 2010 at 3:10 PM, Prajakta Shitole prajakt...@gmail.comwrote: I was able to resolve the issue, just made simple tweaks like removing the drawableMap we just need the imageCache. On Sat, Apr 10, 2010 at 10:51 AM, Prajakta Shitole prajakt...@gmail.com wrote: Forgot to paste my code:- class IconicAdapter extends ArrayAdapter { Activity context; Context context2; HashMapString,String ret = new HashMapString,String(); AsyncLoader async;// = new AsyncLoader(); private ListView listView; HashMapString,Bitmap bit = new HashMapString,Bitmap(); IconicAdapter(Activity context) { super(context, R.layout.exclusive, items); this.context=context; async = new AsyncLoader(); } public View getView(final int position, View convertView, ViewGroup parent) { View row_inflated = View.inflate(context, R.layout.exclusive,null); wrapper = new ViewWrapper(row_inflated); row_inflated.setTag(wrapper); wrapper.getSongName().setText(items[position]); wrapper.getSingerName().setText(singer_name[position]); final ImageView imgview = wrapper.getIcon(); imgview.setTag(myRemoteImages[position]); Bitmap cachedImage = async.loadDrawable(myRemoteImages[position], new ImageCallback() { public void imageLoaded(Bitmap imageBitmap, String imageUrl) { imgview.setImageBitmap(imageBitmap);
[android-developers] Lazy Loading Images in a ListView - consensus approach?
Here are 4 references that I have found for lazy-loading images into a listview in Android. The idea is to display a placeholder image, get the actual image in the background, update the ImageView in the list when the image is available. I've tried to do this in the simplest way possible using an AsyncTask in an Adapter. The outline of that approach is below. Is it flawed? Is there an agreed approach to handling this common task? Thanks, Carmen http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android-part-2/ Tom van Zummeren http://evancharlton.com/thoughts/lazy-loading-images-in-a-listview/ Evan Charlton http://code.google.com/p/shelves/ from Romain Guy http://github.com/commonsguy/cwac-thumbnail from Mark Murphy Approach using AsyncTask within an Adapter Somewhere in the Adapter. Add info about the URL for the image to fetch to the ImageView. Execute an AsyncTask to get the image in the background and load the ImageView. AsyncTask uses the tag to fetch the image. It uses the tag to find the correct view within the ListView. ImageView imageViewByTag = (ImageView) myListView.findViewWithTag(tag); ImageView is updated. Somewhere in the Adapter: myImageView.setTag(http://someimage.jpg;); // try { new GetImage().execute(myImageView); } catch(RejectedExecutionException e) { } // Asynctask private class GetImageInBackground extends AsyncTaskImageView , ImageView , Long { Drawable drawable; String tag; @Override protected void onProgressUpdate (ImageView... params){ if (drawable!=null){ ImageView imageViewByTag = (ImageView) myListView.findViewWithTag(tag); // find the ImageView if (imageViewByTag != null) { imageViewByTag.setImageDrawable(drawable); //update it } } } @Override protected Long doInBackground(ImageView... params) { tag = (String) params[0].getTag(); // get the tag from the ImageView if (tag==null){ drawable = getPlaceholder(); // get a default drawable }else{ bm =getDrawablefromURL(String (tag); // a method to get drawable from a URL } publishProgress(params[0]); return null; } } -- Carmen http://www.twitter.com/CarmenDelessio http://www.talkingandroid.com http://www.facebook.com/BFFPhoto http://www.twitter.com/DroidDrop -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Lazy Loading Images in a ListView - consensus approach?
I haven't looked in details at the 3 other approaches but I know that a big difference between what I do in Shelves and what I've seen done in other places is how user interaction is handled. Shelves listens to scroll events on the ListView and tries to identify taps vs scrolls vs fling to always give priority to the UI. For instance, when you touch the screen to stop a fling, Shelves starts loading images, but does so only after a very short delay so that if you are touching the screen to fling some more, the fling animation won't stutter because of the extra work load. But that's details. On Sat, Feb 13, 2010 at 8:01 PM, Carmen Delessio carmendeles...@gmail.com wrote: Here are 4 references that I have found for lazy-loading images into a listview in Android. The idea is to display a placeholder image, get the actual image in the background, update the ImageView in the list when the image is available. I've tried to do this in the simplest way possible using an AsyncTask in an Adapter. The outline of that approach is below. Is it flawed? Is there an agreed approach to handling this common task? Thanks, Carmen http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android-part-2/ Tom van Zummeren http://evancharlton.com/thoughts/lazy-loading-images-in-a-listview/ Evan Charlton http://code.google.com/p/shelves/ from Romain Guy http://github.com/commonsguy/cwac-thumbnail from Mark Murphy Approach using AsyncTask within an Adapter Somewhere in the Adapter. Add info about the URL for the image to fetch to the ImageView. Execute an AsyncTask to get the image in the background and load the ImageView. AsyncTask uses the tag to fetch the image. It uses the tag to find the correct view within the ListView. ImageView imageViewByTag = (ImageView) myListView.findViewWithTag(tag); ImageView is updated. Somewhere in the Adapter: myImageView.setTag(http://someimage.jpg;); // try { new GetImage().execute(myImageView); } catch(RejectedExecutionException e) { } // Asynctask private class GetImageInBackground extends AsyncTaskImageView , ImageView , Long { Drawable drawable; String tag; @Override protected void onProgressUpdate (ImageView... params){ if (drawable!=null){ ImageView imageViewByTag = (ImageView) myListView.findViewWithTag(tag); // find the ImageView if (imageViewByTag != null) { imageViewByTag.setImageDrawable(drawable); //update it } } } @Override protected Long doInBackground(ImageView... params) { tag = (String) params[0].getTag(); // get the tag from the ImageView if (tag==null){ drawable = getPlaceholder(); // get a default drawable }else{ bm =getDrawablefromURL(String (tag); // a method to get drawable from a URL } publishProgress(params[0]); return null; } } -- Carmen http://www.twitter.com/CarmenDelessio http://www.talkingandroid.com http://www.facebook.com/BFFPhoto http://www.twitter.com/DroidDrop -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Lazy Loading Images in a ListView
I trying a hand at ListViews and my current experiment is aimed at displaying some data in a ListView. The data to be displayed in each row is simple: an image and some text. The images come from a remote server and the textual data is hardcoded. I have a class that downloads images using AsyncTask and caches the list of images fetched as SoftReferences in a LinkedHashMap. I am also passing a reference of the view to this class, so when the image download/cache read is complete the class will set appropriate Bitmap in the view. Following is my code: //class BasicAdapter extends ArrayAdapterRowData ... static class ViewHolder{ TextView text; ImageView icon; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if(convertView == null){ convertView = mInflater.inflate(R.layout.listview_row,null); holder = new ViewHolder(); holder.text = (TextView) convertView.findViewById(R.id.row_txt); holder.icon = (ImageView) convertView.findViewById(R.id.row_img); convertView.setTag(holder); } else{ holder = (ViewHolder) convertView.getTag(); } holder.text.setText(mDataSet.get(position).getMText()); //set default icon holder.icon.setImageResource(R.drawable.icon); // set the actual image from the cache String imageUrl = mDataSet.get(position).getMUrl(); WriteThroughCache.getImage(holder.icon, imageUrl); return convertView; } // My helper class that manages cache and image Download public class WriteThroughCache{ static LinkedHashMapString,SoftReferenceBitmap imageCache = new LinkedHashMapString,SoftReferenceBitmap(); public static void getImage(ImageView icon, String imageUrl){ if(imageCache.containsKey(imageUrl)){ Bitmap image = imageCache.get(imageUrl).get(); if(image != null){ icon.setImageBitmap(image); return; } } new LoadImageInBackground().execute(new Object[]{icon,imageUrl}); } static class LoadImageInBackground extends AsyncTaskObject, Void, Bitmap{ ImageView mIcon = null; String mUrl = null; @Override protected Bitmap doInBackground(Object... params) { mIcon = (ImageView)params[0]; mUrl = (String) params[1]; Bitmap image = BitmapFactory.decodeStream (GetMethodExecutor.getResponseStream(mUrl)); return image; } @Override protected void onPostExecute(Bitmap result) { super.onPostExecute(result); mIcon.setImageBitmap(result); imageCache.put(mUrl, new SoftReferenceBitmap(result)); } } } Problem: The applications seems to work just fine. However, when I touch scroll the screen sometimes, the rows display the default image and Loading.. text. These are never refreshed. But if I fling the listview, everything works normal then. I am not sure of what I am missing here, please guide. Thanks. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en