Category Archives: Android

Pull-to-Refresh ListView for Android

Although this kind of list refreshing is rather an iPhone feature, and not really used on Android platform, sometimes it is requested to use.
An easy to use listener-based implementation can be found here by Johan Nilsson.
Alternative version thanks to Guille Polito.

Update here is another lib, used in Friendcaster and co: Android-PullToRefresh by Chris Banes

Converting View to Bitmap without displaying it

Here is the Android code for converting a View object to Bitmap without displaying it. This can be useful for displaying complex views in a Gallery widget.

Bitmap bmp = Bitmap.createBitmap(Utils.getPixelForDp(width, this), Utils.getPixelForDp(height, this), Bitmap.Config.ARGB_8888);
View v = getLayoutInflater().inflate(layoutid, null);
v.measure(MeasureSpec.makeMeasureSpec(bmp.getWidth(), MeasureSpec.EXACTLY), 
MeasureSpec.makeMeasureSpec(bmp.getHeight(), MeasureSpec.EXACTLY));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); 
v.draw(new Canvas(bmp));

Best source: Stackoverflow.com

Coverflow widget for Android

Very useful example about creating a coverflow widget using the Gallery component provided by the framework:
http://www.inter-fuser.com/2010/02/android-coverflow-widget-v2.html

If you wish to know more about the Gallery widget, here is a good tutorial with examples:
http://android-pro.blogspot.com/2010/07/android-gallery-control.html

An older version of the widget can be found here, however this is much more complicated…