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?

Thanx,

Patrick



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 List13.java example
in the APIDemos? I have a video example of what can be achieved with
such techniques, here:

 http://www.youtube.com/watch?v=QZ8PoS6ai6U 




> 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.

Patrick


2010/1/6 Brion Emde <brione2...@gmail.com>:

>



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?

Vince



> Patrick



Using an image in a listview

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


 i,

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:

@Override
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,
null);

// Creates a ViewHolder and store references to the two
children views
// we want to bind data to.
holder.titleText = (TextView)
convertView.findViewById(R.id.article_title);
holder.descriptionText = (TextView)
convertView.findViewById(R.id.article_description);
holder.icon = (ImageView)
convertView.findViewById(R.id.article_thumb);

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


// Bind the data efficiently with the holder.

holder.titleText.setText(Html.fromHtml(((FeedMessage)Items.get(position)).getTitle()));

holder.descriptionText.setText(Html.fromHtml(((FeedMessage)Items.get(position)).getDescription()));

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 =
_context.getResources().getDrawable(R.drawable.thumb_holder);
holder.icon.setImageDrawable(d);
}
if(fm.getGuid() != null){
convertView.setId(position);
}

return convertView;
}

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



regards,

Patrick

2010/1/6 Vince <specialized...@gmail.com>:
>



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.
holder.titleText.setText(Html.fromHtml(((FeedMessage)Items.get
(position)).g etTitle()));
holder.descriptionText.setText(Html.fromHtml(((FeedMessage)Items.get
(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
about:

// Bind the data efficiently with the holder.
Drawable d = null;
FeedMessage fm = (FeedMessage) Items.get(position);
holder.titleText.setText(Html.fromHtml(fm.getTitle
()));
holder.descriptionText.setText(Html.fromHtml
(fm.getDescription()));



On Jan 6, 12:57pm, Patrick Plaatje <pplaa...@gmail.com> 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!

Best,

Patrick

2010/1/6 Brion Emde <brione2...@gmail.com>:
>> >



Using an image in a listview

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


 i,

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?

Regards,

Patrick


2010/1/6 Patrick Plaatje <pplaa...@gmail.com>:
>>> >



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
intents.
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
manually.

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
in.

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.

Thanks
nleiptv
--~--~---------~--~----~------------~-------~--~----~

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
framework?

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.

Code:

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,
R.styleable.ZN5ScrollView);
                LoadedBitmap = 
BitmapFactory.decodeResource(context.getResources(),
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;
                }

        }

        @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(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;
                }
                break;
        case ZOOM_OUT:
                if (scale > 1.0f) {
                        scale = scale -0.1f;
                }
                break;
        }
        invalidate();
}


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 +
modifierValue);
                }
        }
        else if(distX < -6.0) {
                if(scrollX >= 50) {
                        scrollX = Math.min(IMAGE_WIDTH + SCREEN_WIDTH, scrollX -
modifierValue);
                } else {
                        scrollX = 0;
                }
        }

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

        if((scrollX <= IMAGE_WIDTH) && (scrollY <= IMAGE_HEIGHT)) {
                ViewBitmap = Bitmap.createBitmap(LoadedBitmap, scrollX, scrollY,
SCREEN_WIDTH, SCREEN_HEIGHT);
                invalidate();
        }
}

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;
}


Regards,
Tane
--~--~---------~--~----~------------~-------~--~----~

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