When a card is selected in a CardScrollView
, the onItemSelected()
method is called. However, I cannot determine how to add an image to this card once selected. For now, I've done a kluge callback mechanism where I call updateViews(true)
:
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position == mSelectedPosition)
return;
mSelectedPosition = position;
if (mCardScrollView != null)
mCardScrollView.updateViews(true);
}
Then in the adapter getView()
I check if the item is selected, and if so load the image asynchronously:
if (mCardScrollView != null && mCardScrollView.getSelectedItemPosition() == pos) {
String url = String.format(Board.THUMBNAIL_FORMAT, board, tim);
CardImageLoader.loadCardImage(card, Card.ImageLayout.FULL, url, mCardScrollView);
}
The CardImageLoader
then downloads the file and does yet another call to updateViews()
after the download is successful, finally calling card.addImage()
and the image displays.
This works, but can make things slow at times, and sometimes unresponsive. How to do it better?
UPDATE: Don't use a Card when you need to load a list of cards with images in a CardScrollView. Instead, use your own custom layout to emulate a card and use a standard image loader to do the loading. This works much better even with very long lists.
Google please make the card layout XMLs open so we can use them.