views:

385

answers:

1

I enabled the Linkify property of a textview as follows:

txtbox.setAutoLinkMask(Linkify.WEB_URLS);

But, when there are URLs like bit.ly are present (which is very common nowadays in messages like tweets), it doesn't display them properly. The problem is "sometimes" it succeeds and sometimes it fails... The other problem is, if this TextView is part of a custom view for a ListView, then until I actually scroll the list somehow none of the URLs get linkified...

The other problem is, if there is an image inside a ListView, when I scroll through the list, I can see a different image load before it loads the actual image. I assume this is happening due the recycling of views, but is there any workaround for this?

+2  A: 

But, when there are URLs like bit.ly are present (which is very common nowadays in messages like tweets), it doesn't display them properly.

You don't really explain what "doesn't display them properly" means, so it is difficult to provide advice there. All I can do is point you to a project that uses android:autoLink="all", and I haven't received comments from students or readers that certain URLs aren't working.

If you succeeds/fails reference is with respect to whether or not it gets turned into a link, there may be a bug in the Linkify pattern matching algorithm. Jot down several links that fail and see if you can find a common pattern (e.g., has some funky punctuation).

if there is an image inside a ListView, when I scroll through the list, I can see a different image load before it loads the actual image. I assume this is happening due the recycling of views, but is there any workaround for this?

If you are populating your images immediately, I'm not aware that you will get this effect. I see this when I am loading the images based on work in a background thread (e.g., downloading the images to a cache, then updating the ImageView). One thing to do in that case is to replace the image with a placeholder in your adapter until the real image is ready.

CommonsWare