2013-02-24 104 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

我能夠解決這個問題,通過消除動畫監聽器並在運行我的後期動畫代碼之後添加一個延遲可運行的代碼。

我無法找到在動畫偵聽器內設置新適配器(因爲我使用自定義適配器而必需)的方法。如果有人知道如何做到這一點,我想知道。