Question

I am attempting to use Navadfima's CardsUI for Android here. The problem is I have approximately 1500 bitmaps (each one goes on a card) and even when using the scaling suggestions at the DevDocs I run out of memory. My current plan is to set an onScrollListener in the CardUI activity but I don't know how to make one in a library that I can call from my code.

CardUI class from Library is here

My class:

public class FragmentCardsUI extends Fragment{
private CardUI mCardView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View rootView = inflater.inflate(R.layout.activity_card, container, false);
    getActivity().setTitle("Cards UI");

    // init CardView
    mCardView = (CardUI) rootView.findViewById(R.id.cardsview);

    try {
        setCards();
    } catch (NullPointerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    mCardView.refresh();
return rootView;

How can I modify CardUI so I can set an onScrollListener in my code so I can tell when a card is visible and subsequently load a bitmap to it?

Was it helpful?

Solution 2

Never found a good solution for this so I switched libraries to use Nostra's Universal Image Loader. This library appears to still be in development as opposed to the CardsUI library (hasn't had a change in over 7 months but there are plenty of requests).

OTHER TIPS

Have you looked into com.fima.cardsui.StackAdapter.java getView(int position, View convertView, ViewGroup parent) method?

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final CardStack stack = getItem(position);
    stack.setAdapter(this);
    stack.setPosition(position);

    // TODO: caching is not working well

    // if (convertView != null) {
    // CardStack tagStack = (CardStack) convertView.getTag();
    // ArrayList<Card> tagCards = tagStack.getCards();
    // ArrayList<Card> cards = stack.getCards();
    // Card lastTagCard = tagCards.get(tagCards.size()-1);
    // if (!lastTagCard.equals(cards.get(cards.size()-1))) {
    // convertView = stack.getView(mContext);
    // convertView.setTag(stack);
    // }
    // } else if (convertView == null) {
    convertView = stack.getView(mContext, mSwipeable);
    // convertView.setTag(stack);
    // }

    return convertView;
}

I believe, that's the reason you are getting OME. It doesn't use ViewHolder pattern, instead it tries to load everything again.

Also looked into com.fima.cardsui.objects.CardStack and you can guess what happens when you try to create 1500 Views.

I recommend you to modify the source.

In case u want to implement the scroll down for the CardsUI Lib . Just add the following :

android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"

You need to add the lines in cards_view.xml Layout . Here is how the file will look after update :

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<com.fima.cardsui.views.QuickReturnListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@android:color/transparent"
    android:dividerHeight="4dp"
    android:listSelector="@android:color/transparent"
    android:overScrollMode="never"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:scrollbars="vertical" 
    android:stackFromBottom="true"
    android:transcriptMode="alwaysScroll">
</com.fima.cardsui.views.QuickReturnListView>

<FrameLayout
    android:id="@+id/sticky"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:visibility="gone" />

</FrameLayout>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top