ribot / easy-adapter

[DEPRECATED] Easy Adapters library for Android
http://ribot.github.io
Apache License 2.0
421 stars 50 forks source link

Add Item from ctr VS. Add item by method #36

Closed objque closed 8 years ago

objque commented 8 years ago

Hello, if i try write this code:

empty

I have empty listView. But if i write this code: not empty

Then already ok, What I'm doing wrong? I use retrofit+your library

ivacf commented 8 years ago

Hi,

EasyAdapter has several constructors but there isn't one to add a single item. The one you are using in the first case is:

/**
     * Constructs and EasyAdapter with a Context, an {@link ItemViewHolder} class and a generic listener.
     *
     * @param context             a valid Context
     * @param itemViewHolderClass your {@link ItemViewHolder} implementation class
     * @param listener            a generic object that you can access from your {@link ItemViewHolder} by calling
     *                            {@link ItemViewHolder#getListener()}, This can be used to pass a listener to the view holder that then you
     *                            can cast and use as a callback.
     */
    public EasyAdapter(Context context, Class<? extends ItemViewHolder> itemViewHolderClass, Object listener) {
        super(context, itemViewHolderClass, listener);
        mListItems = new ArrayList<>();
    }

As you can see, the third parameter is a generic object that is intended to pass a listener/callback to your view holder, so the third parameter is NOT a data item for the adapter and that's why your code is not working. If you want, you can pass a list of data items in the constructor but not a single one.