Using an image in a listview

by Patrick Plaatje » Wed, 06 Jan 2010 23:18:36 GMT

Sponsored Links
 Hi all,

for my app i'm using a listview to display rss news articles. All goes
well, and the implementation is almost done. But when using my app,
i'm not really satisfied with the "smoothness" and user experience of
it. The main problem is that when i scroll through the listview, which
contains an image for each row in the listview, the scrolling isn;t
smooth, it executes the getview override every time. I already threw
out the "holder startegy", as it slowed the scrolling...

any thoughts?



Using an image in a listview

by Brion Emde » Thu, 07 Jan 2010 00:22:52 GMT

 Are you using any of the techniques shown in the example
in the APIDemos? I have a video example of what can be achieved with
such techniques, here: 

> Patrick

Sponsored Links

Using an image in a listview

by Patrick Plaatje » Thu, 07 Jan 2010 00:28:59 GMT

 Hi Brion,

thanks, i will certainly give that a try. But the funy thing is that
i'm actually not attaching that much data to my listview rows. I even
stripped the images from it and i still have some "hickups" when
scrolling. And it's indeed probably the getview method which tries to
attach the data to the view.

But as said i'll give the example a go and see if that helps. Many
thanx in advance.


2010/1/6 Brion Emde <>:


Using an image in a listview

by Vince » Thu, 07 Jan 2010 03:52:17 GMT

 What does your getView code look like. Are re-inflating your row view
every time it's called, are there multiple views for the rows etc?


> Patrick

Using an image in a listview

by Patrick Plaatje » Thu, 07 Jan 2010 03:58:04 GMT


i've used the holder method, but adding or omitting this didn;t give
me an increase or decrease in performance, my getView method is below:

public View getView(int position, View convertView, ViewGroup parent) {

// A ViewHolder keeps references to children views to avoid
unneccessary calls
// to findViewById() on each row.
ViewHolder holder;

holder = new ViewHolder();

// When convertView is not null, we can reuse it directly,
there is no need
// to reinflate it. We only inflate a new View when the
convertView supplied
// by ListView is null.
if (convertView == null){
convertView = mInflater.inflate(R.layout.article_row,

// Creates a ViewHolder and store references to the two
children views
// we want to bind data to.
holder.titleText = (TextView)
holder.descriptionText = (TextView)
holder.icon = (ImageView)

} else {
// get holder back...much faster than inflate
holder = (ViewHolder) convertView.getTag();

// Bind the data efficiently with the holder.



Drawable d = null;
FeedMessage fm = (FeedMessage) Items.get(position);

if(fm.getEnclosures().size() > 0){
String urlString = fm.getEnclosures().get(0);
dm.fetchDrawableOnThread(urlString, holder.icon);
} else {
d =
if(fm.getGuid() != null){

return convertView;

static class ViewHolder {
TextView descriptionText;
TextView titleText;
ImageView icon;



2010/1/6 Vince <>:

Using an image in a listview

by Brion Emde » Thu, 07 Jan 2010 05:06:31 GMT

  see some problems here:

// Bind the data efficiently with the holder.
(position)).g etTitle()));
(positi on)).getDescription()));
Drawable d = null;
FeedMessage fm = (FeedMessage) Items.get(position);

if that Items.get(position) is costly, you're wasting it, above. How

// Bind the data efficiently with the holder.
Drawable d = null;
FeedMessage fm = (FeedMessage) Items.get(position);

On Jan 6, 12:57pm, Patrick Plaatje <> wrote:
> >

Using an image in a listview

by Patrick Plaatje » Thu, 07 Jan 2010 05:20:33 GMT

 i Brion,

if this arraylist would be a rather big list, it would be costly
indeed, and it is a good suggestion. This list consists of just 10
items (feedmessage objects) though. These feedmessages are just a set
of getters and setters (of just small String objects) and are not doin
any costly operations internally.

I will try your suggestion though to see if this will help. I'm kinda
clueless on what is so costly............

Thanx for the suggestions, and will let you know tomorrow!



2010/1/6 Brion Emde <>:
>> >

Using an image in a listview

by Patrick Plaatje » Thu, 07 Jan 2010 18:05:18 GMT


i've tried the list13 implementation, but although scrolling seems
smoother then it ever was, i'm kinda displeased with the time it takes
to fill the rows with content. I think my main concern is related to
the reuse of the rows, rather then how to fill them. I am wondering if
there isn't a way to prefill the listview and don;t reuse anything?



2010/1/6 Patrick Plaatje <>:
>>> >

Other Threads

1. How to return to an auto-started activity

Hi everyone,

I have been searching till my fingers bled, so now I decided to ask
here for help.
I have the following problem:
I have written an activity which I start up as soon as the phone has
finished booting.
For that I used a Broadcast receiver that listens to BOOT_COMPLETED
All that works fine and the activity is started as planned.
The activity also shows up in the launcher list, i.e. can be started

When the broadcast receiver starts the activity it does so using the
flag Intent.FLAG_ACTIVITY_NEW_TASK, to make sure that the activity
(which is not started in any context on autostart) has a task to run

Problem is that if a user interacts with the autostarted activity and
then presses the home-button, goes to the launcher menu and selects
the activity manually, a new instance is started in another task ( i
guess the launcher's task).
What do I have to do to allow the user to return to the activity (and
task) that was started after boot up?

Is there a way to - say - get the task ID from somehwere, then store
that statically and in onCreate() first check if there is a running
task already and if so bring that to the front instead of starting a
new instance?

Any help is greatly appreciated.


2. Canvas Scaling issues

Hey folks,

A few weeks ago I posted a view I was working on and in that time I
have improved the view a lot, but I've been asked to add a new
features of zooming into the image.

The view is a custom image viewer that allows large images (such as
640x1000) to be loaded, and the user to scroll around using either the
touchscreen or trackball on the device.  The code below is reasonably
succesful in that it works at the default scale level of 1.

But with addign zooming, instead of zooming into the 'centre' of the
location the user is looking at, and allowing the user to move around
the whole of the image at this level it instead zooms into the top and
left of the location, and in doing so it starts to cut off the bottom
and right of the image whole, so while zoomed in you cannot go any
ruther right or down in the image, but you can go to the top and left
easily enough.

The best example of what I am trying to achive is the Image viewer in
the camera application.

So my two questions are:

1) Can anyone suggest how I can fix this in the canvas or
2) Is there a better way to do this with an existing feature in the

I'm probably thinking it's something to do with the modifierValue when
scrolling around that I somehow need to increase this, but trying this
causes my activity to crash.


public class ZN5ScrollView extends View {

        public ZN5ScrollView(Context context, AttributeSet attrs) {
                super(context, attrs);

                scrollX = 0;
                scrollY = 0;
                scale = 1.0f;
                modifierValue = 50;

                ViewPaint = new Paint();

                TypedArray a = context.obtainStyledAttributes(attrs,
                LoadedBitmap = 
a.getResourceId(R.styleable.ZN5ScrollView_src, R.drawable.icon));

                IMAGE_WIDTH = LoadedBitmap.getWidth();
                IMAGE_HEIGHT = LoadedBitmap.getHeight();

                ViewBitmap = Bitmap.createBitmap(LoadedBitmap);

        protected void onSizeChanged  (int w, int h, int oldw, int oldh) {
                SCREEN_WIDTH = w;
                SCREEN_HEIGHT = h;

                if (IMAGE_WIDTH < SCREEN_WIDTH) {
                        IMAGE_WIDTH = SCREEN_WIDTH - scrollX;
                if (IMAGE_HEIGHT < SCREEN_HEIGHT) {
                        IMAGE_HEIGHT = SCREEN_HEIGHT - scrollY;


    protected void onDraw(Canvas canvas) {
        canvas.scale(scale, scale);
        canvas.drawBitmap(ViewBitmap, 0f, 0f, ViewPaint);

public void handleView(int zoomType) {
        switch (zoomType) {
        case ZOOM_IN:
                if (scale <= 1.5f) {
                        scale = scale + 0.1f;
        case ZOOM_OUT:
                if (scale > 1.0f) {
                        scale = scale -0.1f;

public void handleScroll(float distX, float distY) {
        /* X-Axis */
        if(distX > 6.0) {
                if(scrollX < IMAGE_WIDTH) {
                        scrollX = Math.min(IMAGE_WIDTH - SCREEN_WIDTH, scrollX +
        else if(distX < -6.0) {
                if(scrollX >= 50) {
                        scrollX = Math.min(IMAGE_WIDTH + SCREEN_WIDTH, scrollX -
                } else {
                        scrollX = 0;

        /* Y-Axis*/
        if(distY > 6.0) {
                if(scrollY < IMAGE_HEIGHT) {
                        scrollY = Math.min(IMAGE_HEIGHT - SCREEN_HEIGHT, 
scrollY +
        else if(distY < -6.0) {
                if(scrollY >= 50) {
                        scrollY = Math.min(IMAGE_HEIGHT + SCREEN_HEIGHT, 
scrollY -
                } else {
                        scrollY = 0;

        if((scrollX <= IMAGE_WIDTH) && (scrollY <= IMAGE_HEIGHT)) {
                ViewBitmap = Bitmap.createBitmap(LoadedBitmap, scrollX, scrollY,

private int modifierValue;

private float scale;
public final int ZOOM_IN = 1;
public final int ZOOM_OUT = 2;

private int SCREEN_WIDTH;
private int SCREEN_HEIGHT;

private int IMAGE_WIDTH;
private int IMAGE_HEIGHT;

private int scrollX;
private int scrollY;

private Bitmap LoadedBitmap;
private Bitmap ViewBitmap;
private Paint ViewPaint;


3. SystemServer permissions ..

4. Camera Captured Image not Saving

5. Android Market :: Free application gets to top of pile on new release, paid app doesn't?

6. Android build didn't create contents of /data directory

7. how should i buy apps