1
我的應用程序有一個滑動抽屜通知。我設法讓它像android通知一樣運行,包括「全部清除」按鈕。動畫後更新ListView
當清除所有按鈕被點擊時,我的數據庫被清除,我的列表適配器被刷新,我的列表適配器被設置爲列表。視圖更新和列表被清除。
當我添加滑出動畫(就像果凍豆),我得到了一個NullPointerException。當我的適配器被設置時,問題就會出現。如果我註釋掉設置適配器的動畫運行沒有問題。
// 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);
執行時。我在我的應用程序中使用了這種方法和適配器,正如我上面所說的,它在沒有動畫的情況下完美地工作。