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. Emulator on Linux 10 times slower than on Windows

I had this problem with Ubuntu 8.10, two things :
- check that you're using the good environment x86 / 64
- use preferly the SUN JDK 1.6  to compile Android development (you
can use the JDK 1.5 to work with sources).

Today I'm using a bipro intel, 4Gb, Ubuntu 9.10 and SUN JDK 1.5.0.20
and performance are really good.

BR

On Dec 7, 5:49pm, Michael MacDonald <googlec...@antlersoft.com>









-- 

2. Emulator on Linux 10 times slower than on Windows

I've had bad Linux/hardware interactions with the emulator from audio. 
The emulator AFAIK uses the SDL audio libraries.  Try starting the
emulator from the command line with the -noaudio flag and see if that
works better.








-- 

3. Socket refused connection

4. Help! No files return from apache commons net FTPClient

5. concept: app that pulls data from a website

6. including an XML-defined layout in another XML-defined layout

7. HTML sanitization