Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does it support non sticky footer? #142

Closed
laukaichung opened this issue Jun 20, 2016 · 5 comments
Closed

Does it support non sticky footer? #142

laukaichung opened this issue Jun 20, 2016 · 5 comments
Assignees
Labels

Comments

@laukaichung
Copy link

laukaichung commented Jun 20, 2016

Read this #68
but I still don't understand how to use FooterAdapter to add a non-sticky footer to the recyclerlist.
Suppose I have an xml layout as a footer,

<LinearLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
       <Button
                android:id="@+id/delete_item"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Delete"/>
</LinearLayout>

what is the way of adding this layout as a footer to the adapter ? I'm not sure what to add to footerAdapter.add().

Took a shot in the dark after reading this tutorial:

FooterView:

public class FooterView extends AbstractItem<FooterView, FooterView.ViewHolder> {
    public FooterView() {
    }

    @Override
    public int getType() {
        return R.id.footer;
    }
    @Override
    public int getLayoutRes() {
        return R.layout.footer;
    }
    @Override
    public void bindView(ViewHolder holder) {
        super.bindView(holder);
        holder.pagerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                     // sth action
            }
        });
    }
    protected static class ViewHolder extends RecyclerView.ViewHolder {
        View pagerButton;
        public ViewHolder(View itemView) {
            super(itemView);
            pagerButton = itemView.findViewById(R.id.delete_item);
        }
    }
}

In the Activity.class:

GenericItemAdapter<ItemModel, ItemAdapter> adapter = new GenericItemAdapter<>(ItemAdapter.class, ItemModel.class);
fastAdapter = new FastAdapter();
fastAdapter.withSelectable(false);
FooterAdapter<FooterView> footerAdapter = new FooterAdapter();
footerAdapter.add(new FooterView());
GridLayoutManager gridLayoutManager = new GridLayoutManager(this,2);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(footerAdapter.wrap(adapter.wrap(fastAdapter)));
adapter.addModel(productItem);

But I am getting errors at footerAdapter.add(new FooterView());

java.lang.NullPointerException
at com.mikepenz.fastadapter.AbstractAdapter.mapPossibleType(AbstractAdapter.java:244)
at com.mikepenz.fastadapter.AbstractAdapter.mapPossibleTypes(AbstractAdapter.java:233)
at com.mikepenz.fastadapter.adapters.ItemAdapter.add(ItemAdapter.java:323)
at com.mikepenz.fastadapter.adapters.ItemAdapter.add(ItemAdapter.java:309)

I have also tried the same with HeaderAdapter. It also shows the same error with the add() method.

@mikepenz mikepenz self-assigned this Jun 20, 2016
@mikepenz
Copy link
Owner

@laukaichung
Copy link
Author

Do you mean I need to use FastScrollIndicatorAdapter and wrap the footeradapter with it?

@mikepenz
Copy link
Owner

@stonecold123 you have the GenericItemAdapter and the FooterAdapter so you need to do the following (the above link was just a sample)

footerAdapter.wrap(adapter);

and you then apply the footerAdapter to the RecyclerView

@laukaichung
Copy link
Author

laukaichung commented Jun 21, 2016

Thanks mike,just solved it. Also, I should have put footerAdapter.add(new FooterView()); after the the adapters are set.

FooterAdapter<FooterView> footerAdapter = new FooterAdapter();
GridLayoutManager gridLayoutManager = new GridLayoutManager(this,2);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(footerAdapter.wrap(adapter.wrap(fastAdapter)));
adapter.addModel(productItem);
footerAdapter.add(new FooterView());

@mikepenz
Copy link
Owner

@stonecold123 yes correctly the FooterAdapter already needs the global FastAdapter because the FastAdapter will manage everything. and without this it will fail too.

(In your case the FastAdapter is the GenericItemAdapter which is FastAdapter + 1 GenericItemAdapter combined)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants