TonicArtos / StickyGridHeaders

This project has been superseded by SuperSLiM, a layout manager for RecyclerView. I strongly recommend using SuperSLiM and not StickyGridHeaders.
http://tonicartos.com
Apache License 2.0
1.47k stars 442 forks source link

NPE when using an Animation on a View #35

Closed fmweigl closed 6 years ago

fmweigl commented 11 years ago

I use this code inside getView to animate the deletion of an item from my Adapter (extends BaseAdapter implements StickyGridHeadersBaseAdapter):

final View myView = holder.root; // Any view from the inflated item layout

holder.Deletebtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Animation anim = AnimationUtils.loadAnimation(ctx,
                    android.R.anim.slide_out_right);

            anim.setAnimationListener(new Animation.AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {

                    removeTheItemFromTheUnderlyingListOfItems(); 
                    notifyDataSetChanged(); 

                }
            });

            myView.startAnimation(anim);

        }
    });

This works when setting

StickyGridHeadersGridView gv = ...
gv.setAreHeadersSticky(false); 

else it fails with:

FATAL EXCEPTION: main
java.lang.NullPointerException
at com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView.dispatchDraw(StickyGridHeadersGridView.java:748)
at android.view.View.draw(View.java:11180)
at android.widget.AbsListView.draw(AbsListView.java:3769)

I don't know if this is a bug or I'm doing something wrong, but my code works for standard GridViews and ListViews.

TonicArtos commented 11 years ago

There are probably all sorts of things wrong with animations. I want to get the header view hierarchy problem resolved before I tackle this.

TonicArtos commented 11 years ago

It is possible that this issue has been resolved. I'd appreciated it if you could try your code with the latest changes in master. Thanks.

fmweigl commented 11 years ago

I will try it and give feedback, thanks.