开发者

animating wrong listview image

开发者 https://www.devze.com 2023-03-12 07:06 出处:网络
ok so I have an ExpandableListView,I have defined all my views and everything works well. But now what I need is to have an animation when a group expands and collapse.

ok so I have an ExpandableListView, I have defined all my views and everything works well. But now what I need is to have an animation when a group expands and collapse.

So I have an image in the header of the group xml, then I write.

listView.setOnGroupClickListener(new OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView parent, View v,
                int groupPosition, long id) {


            TextView tv1 = (TextView) v.findViewById(R.id.txtGroupName);
            ImageView tv = (ImageView) v.findViewById(R.id.dropdownarrow);

            Animation a = AnimationUtils.loadAnimation(TabHome.this,
                    R.anim.rotatearrowup);

            if (listView.isGroupExpanded(groupPosition)) {                  

                tv.clearAnimation();                    
                a.setFillAfter(true);                   
                tv.setAnimation(a);                 
                a.start();          

                a.setAnimationListener(new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        adapterSub.notifyDataSetChanged();                          
                    }
        开发者_JAVA技巧        });
            }                   

            return false;
        }
    });

now when I click on a group header or the view, it animates the wrong view. It would animate either the row below or the row above.

Can anyone tell me what I'm doing wrong? Or how could solve this?


Do you handle value int groupPosition somewhere in your code? The problem most possibly is outside this snippet.

0

精彩评论

暂无评论...
验证码 换一张
取 消