I have read a lot of tutorials about animation of the rows, but all of them describe how to animate the selected row. I managed to do it. But the there is a problem. When the row is removed with an animation, I remove data from the adapter and call notifyDataSetChanged(); The rows (below the removed row) go up without animation. How can I achieve the animation of these rows? I want them to slide up smoothly.
            Asked
            
        
        
            Active
            
        
            Viewed 1,783 times
        
    1 Answers
2
            Remove the list item on item click, Hope this code will helpful for you
 listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                    final int position, long id) {
                // TODO Auto-generated method stub
                Animation anim = AnimationUtils.loadAnimation(view.getContext(),
                        android.R.anim.slide_out_right);
                anim.setDuration(500);
                view.startAnimation(anim);
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        strings.remove(position);
                        mAdapter.notifyDataSetChanged();
                    }
                }, anim.getDuration());
            }
            });
UPDATE
Just keep in mind the architecture framework which works when the notifydatasetChanged() is called.
- The getView method is called
- On the call of get view, it will reconstruct all the rows for the list view.
In your case, we have to animate the getView method ( which is to be called again on the action of the notifydatasetchanged). Here is the solution :
/**
       * Hear strings is the data set
       */
      @Override
        public View getView(final int position, View convertView,
                ViewGroup parent) {
            final String str = this.strings.get(position);
            final Holder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(
                        android.R.layout.simple_list_item_1, null);
                convertView.setBackgroundColor(0xFF202020);
                holder = new Holder();
                holder.textview = (TextView) convertView
                        .findViewById(android.R.id.text1);
                holder.textview.setTextColor(0xFFFFFFFF);
                convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }
            holder.textview.setText(str);
            Animation animation = null;
            animation = new ScaleAnimation((float) 1.0, (float) 1.0, (float) 0,
                    (float) 1.0);
            animation.setDuration(750);
            convertView.startAnimation(animation);
            animation = null;
            return convertView;
        }
Please check if it works and let me know if it was useful/helpful to you.
 
    
    
        Ashish Dwivedi
        
- 8,048
- 5
- 58
- 78
- 
                    in your code you show how to animate the selected row. In my question I.m talking about animation of others rows when the selected one was removed. I want that after notifyDataSetChanged(); is called the rows go up with animation. – Alexey Jan 15 '13 at 10:22
