2017-01-07 3 views
0

私はlistViewを持っていて、そこから項目を削除したいと思います。アニメーションが2回呼び出されました

ユーザーが右から左にスライドした後、離れるアイテムのアニメーションが開始されます。次に、この項目を削除する必要があります。

マイコード:

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
     if(convertView==null){ 
      convertView = layoutInflater.inflate(R.layout.note,null); 
     } 
     final RelativeLayout relativeLayout = (RelativeLayout) convertView.findViewById(R.id.relativeLayout); 
     TextView textView = (TextView) convertView.findViewById(R.id.textView9); 
     textView.setText(arrayList.get(position)); 
     Button button = (Button) convertView.findViewById(R.id.button10); 
     button.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       if (event.getAction() == MotionEvent.ACTION_DOWN) { 
        x = event.getX(); 
       } 
       if (event.getAction() == MotionEvent.ACTION_UP) { 
        if (Math.abs(event.getX() - x) > (float)150) { 
         Log.e("Point_1", "Begin animate"); 
         arrayList.remove(position); 
         ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(relativeLayout, "x", 0 - relativeLayout.getWidth()); 
         objectAnimator.setDuration(600); 
         objectAnimator.start(); 
         Log.e("Point_1", "Start removing"); 

         ListViewAdapter.this.notifyDataSetChanged(); 
        } 
       } 
       return false; 
      } 
     }); 
} 

私は私のアプリを実行すると、ほとんどすべてがうまく行きます。スライディング後にアイテムが削除されます。ビューを削除するアニメーションもうまくいきます。しかし!何とか私のビューを削除している直後のアイテムは、アニメーションも開始し、アニメーションの後ではlistViewから削除されません。なにが問題ですか?

enter image description here

そして後に(3つの項目 - 2つのテキスト):削除する前に

enter image description here

答えて

0

誰かが今までこのような問題があります場合。

プロジェクトのresフォルダに新しいディレクトリ "anim"を作成します。次に、必要なアニメーションを作成します。あなたのクラス(-es)でこれらを書いてください

final Animation animation1 = AnimationUtils.loadAnimation(context,R.anim."name of animation that you've already created"); 
animation1.setAnimationListener(new Animation.AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation) { 

      } 

      @Override 
      public void onAnimationEnd(Animation animation) { 
      //Do whatever you've wanted to do. In my case I remove item from listView. 

       arrayList.remove(position); 
       ListViewAdapter.this.notifyDataSetChanged(); 
      } 

      @Override 
      public void onAnimationRepeat(Animation animation) { 

      } 
     }); 
関連する問題