Created
April 1, 2011 07:41
-
-
Save abscondment/897860 to your computer and use it in GitHub Desktop.
Using the lazy-gallery components.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gallery = Gallery(findViewById R.id.lazy_gallery) | |
# Make sure the GallerySelectionListener is only | |
# triggered when the gallery is stopped on an image. | |
gallery.setCallbackDuringFling false | |
# Create our adapter | |
gallery_adapter = LazyGalleryAdapter.new self | |
# When the current item is clicked, create a toast with its caption. | |
this = self | |
gallery.setOnItemClickListener do |parent, view, pos, id| | |
if view.isSelected | |
item = Map(gallery_adapter.getItem pos) | |
c = String(item.get 'caption') || "Item #{pos} (no caption)" | |
Toast.makeText(this, c, Toast.LENGTH_SHORT).show | |
end | |
end | |
# Add the adapter and the selection listener | |
gallery.setAdapter gallery_adapter | |
gallery.setOnItemSelectedListener GallerySelectionListener.new(TextView(findViewById R.id.lazy_gallery_text)) | |
# Expire any old cached images | |
LazyImageView.purgeDiskCache(self) | |
# And finally, send the adapter its data. | |
# A real application will likely abstract away the JSON string details. | |
gallery_adapter.update_from_json json_string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment