4

How do you update a Glass CardScrollView programatically in XE16 (KitKat)?

I have a CardScrollView of cards that display photos from url's. I download the photos from the url's in a background thread and then I want to "refresh" or update the CardScrolView to make the cards display the new images.

I was calling:

cardScrollView.updateViews(true);

In XE12, but in XE16/KitKat that operation is deprecated. So how do you download an image in the background and then update a displayed "Card" with that image? Just calling card.addImage() seems to add a blank image and doesn't display the image.

I've updated my call from the background thread to be:

cardScrollView.getAdapter().notifyDataSetChanged();

Here is the code for the card scroll adapter with

private class SpecialCardsScrollAdapter extends CardScrollAdapter {

    @Override
    public int getPosition(Object item) {
        return specialCardsList.indexOf(item);
    }

    @Override
    public int getCount() {
        return specialCardsList.size();
    }

    @Override
    public Object getItem(int position) {
        return specialCardsList.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return specialCardsList.get(position).getView();
    }

}

Should I expect that calling cardScrollView.getAdapter().notifyDataSetChanged(); would cause Cards already put into the scrollview to update the image they have stored?

MikeN
  • 45,039
  • 49
  • 151
  • 227

1 Answers1

4

As mentioned in the release notes, use BaseAdapter#notifyDataSetChanged() from your CardScrollAdapter instead.

Alain
  • 6,044
  • 21
  • 27
  • How do you invoke that syntax? Are you casting the cardScrollView to Base Adapter? Can you give a code sample? – MikeN Apr 16 '14 at 23:48
  • The `CardScrollAdapter` extends the `BaseAdapter` class: call this method from your adapter, not your view. – Alain Apr 17 '14 at 16:09
  • ok, even with that call the images on the existing cards aren't being updated. – MikeN Apr 17 '14 at 18:29