views:

232

answers:

2

Hi, I have a gallery and when a image is selected, I want to start new thread (for loading other images). But I don't want to do it while the gallery is scrolling. How can I know the state of the gallery and if it is still scrolling?

I can't use "setCallbackDuringFling(false)" because I have a textview under the image that has to be updated during the scrolling...

Thanks! Marc

A: 

I think you could have a go with setCallbackDuringFling method. From what I understand, if you set it to false, it shouldnt be possible to select an item while fling is being computed.

Sephy
Hi Sephy, thanks! the problem is that I have under the image a Textview that I have to update while it is scrolling. If I use setCallbackDunringFling the text is not updated either but I wan't to update it =)
marc
What do you display in your TextView? why do you need to update it while scrolling?
Sephy
I display the name of the picture and its position (in the onItemSelected method) so the user knows where he is and can continue scrolling if he needs to (does not need to wait until it stops for the position and name to be displayed)
marc
oh ok so you have stuff to do when it's scrolling and when it's not. Sorry, don't know how to deal with that.
Sephy
A: 

Use a Handler that is called from the onItemSelectedListener that updates the last time that an item was selected (every time the foremost item changes this listener is fired) and use a timeout value to determine when scrolling ended to determine if scrolling is still occurring.

However, I have the exact same thing in andAMP... I have a FrameLayout with a Gallery and 2 textviews to show the foremost selected Artist and Album... I use onItemSelectedListener to update those TextViews and it works fine. If you have the TextViews in a FrameLayout like me you have to use bringChildToFront to get them to show over the Gallery (add the Gallery last).

As far as Lazy Loading (which I am assuming that is what you are doing). There are a couple of great tutorials about how to do this.

http://ballardhack.wordpress.com/2010/04/05/loading-remote-images-in-a-listview-on-android/ http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html

androidworkz
Thanks! I had to do some tests to find the right timeout value but it seems to work! nice app by the way. How are you loading the images in the gallery ? =)
marc
I wrote an Obervable object that represents the image and I subclassed the ImageView to implement Observer. If the image doesn't exist in the cache folder, I place a default image in the imageview .setBackgroundDrawable and start a thread to process the image... when that thread completes I send an update notification to the imageview and it reloads the image object and sets the background image. I store the image objects in a weakreference hashmap and set the imageview tag to to the index of the object in the hashmap... it's how the imageview knows what object it has referenced.
androidworkz
andAMP is still a work in progress but I appreciate the comment. :)
androidworkz
Hi, I couldn't find any email adress on your website, you can I contact you? I would like to ask you a question related to your implementation, I don't know if here is the right place... Thanks in advance...
marc
http://www.androidworkz.com
androidworkz
Hi, I said before, I must be blind but I can not find any email or contact page on your website... Could you please post a video of your andAMP when fast scrolling through the gallery ? =)
marc
you can email me at admin@I have a video camera but am not that motivated to create a video until I have more bugs worked out... there are two issues in particular that are driving me nuts... I am getting bug reports of the app crashing during rotation (when I look at the log it shows that the menu it open... I am not sure how to save that). Secondly, sometimes the app crashes when people rotate while the progress box is open (like they are updating the album covers and rotate the phone). See a theme? Damn life cycle anyway... :P
androidworkz