2013-02-24 98 views
1

我的应用程序有一个滑动抽屉通知。我设法让它像android通知一样运行,包括“全部清除”按钮。动画后更新ListView

当清除所有按钮被点击时,我的数据库被清除,我的列表适配器被刷新,我的列表适配器被设置为列表。视图更新和列表被清除。

当我添加滑出动画(就像果冻豆),我得到了一个N​​ullPointerException。当我的适配器被设置时,问题就会出现。如果我注释掉设置适配器的动画运行没有问题。

  // Animation 
     int count = drawer_list.getCount(); 
     for (int i = 0; i < count; i++) { 
      View view = drawer_list.getChildAt(i); 
      if (view != null) { 
       // create an Animation for each item 
       Animation animation = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); 
       animation.setDuration(300); 

       // ensure animation final state is "persistent" 
       animation.setFillAfter(true); 

       // calculate offset (bottom ones first, like in notification panel) 
       animation.setStartOffset(300 * (count - 1 - i)); 

       // animation listener to execute action code 
       if (i == 0) { 
        animation.setAnimationListener(new AnimationListener() { 

         public void onAnimationStart(Animation animation) { 
          // NOT USED 

         } 

         public void onAnimationRepeat(Animation animation) { 
          // NOT USED 

         } 

         public void onAnimationEnd(Animation animation) { 

          // Clear table 
          notifications.flushNotificationTempTable_ActiveOnly(); 
          // Update list adapter 
          refreshNotifications(); 
          // Close drawer 
          notification_drawer.close(); 
         } 
        }); 
       } 

       view.startAnimation(animation); 
      } 
     } 

麻烦的斑点是在refreshNotifications()方法中的线drawer_list.setAdapter(notificationAdapter);执行时。我在我的应用程序中使用了这种方法和适配器,正如我上面所说的,它在没有动画的情况下完美地工作。

回答

0

我能够解决这个问题,通过消除动画监听器并在运行我的后期动画代码之后添加一个延迟可运行的代码。

我无法找到在动画侦听器内设置新适配器(因为我使用自定义适配器而必需)的方法。如果有人知道如何做到这一点,我想知道。