1

我有這個主要ListView(檢索使用this.getListView())在從SQLite數據庫正確填充的ListActivity。點擊其中一個項目(條目)使用startActivityForResult()調用另一個活動A2。我想爲用戶回到ListActivity時的SINGLE條目製作動畫。 (所以我想我需要覆蓋onActivityResult()方法)如何在列表已更新和繪製後爲單個項目(條目)設置動畫?

我怎樣才能動畫一個單一的條目,一旦窗口獲得焦點和列表更新後使用notifyDataSetChanged()

我設法用動畫

getListView().setAnimation(anim) 

整個ListView和工作的罰款。但是,當我這樣做時:

getListView().getChildAt(position).setAnimation(anim) 

什麼也沒有發生。

編輯:這是我的onActivityResult代碼

protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) { 

    super.onActivityResult(requestCode, resultCode, intent); 

    if(resultCode==RESULT_OK && requestCode==SOME_REQUEST_CODE){ 

     Animation anim = new AlphaAnimation(1.0f,0.0f); 
     anim.setFillAfter(true); 
     anim.setDuration(400); 
     anim.setRepeatMode(Animation.REVERSE); 
     anim.setRepeatCount(7); 
     // Just for testing, I chose the first item of the ListView (position=0) 
     tr_adapter.getView(0, getListView().getChildAt(0), getListView()).setAnimation(anim); 

     tr_adapter.notifyDataSetChanged(); //Nothing happens 

    } 

} 

回答

1

在表中設置一個標誌並在您的列表適配器調用notifyDataSetChanged()。在你的列表中有getView()適配器根據表中的標誌確定要做什麼(基於動畫或不)。我會發布一些示例代碼,但我是移動的。

編輯


在你onActivityResult(),標誌(有一些價值,布爾,1/0,等等)在您的數據的數據點設置您想要的動畫。然後在適配器上撥打notifyDataSetChanged()。假設你有一個自定義列表適配器,讓你的getView()函數打開或關閉動畫(或默認關閉並在給定標誌時翻轉它)。

public View getView (int position, View convertView, ViewGroup parent){ 

    // All the standard getView() stuff 

    if (listitem.shouldAnimate()) 
     // animate 
} 
+0

感謝您的回覆Jsimon,但我並沒有真正瞭解您的方法。如果你能留下一個例子,那將是非常棒的。 – Maruen

+1

提示:「假設您有一個自定義列表適配器...」。如果您沒有自定義列表適配器,那麼您需要創建一個,以便您可以將動畫代碼添加到getView(...)方法中,如上所述。看看這個教程http://www.vogella.com/articles/AndroidListView/article.html –

+0

謝謝阿科斯Cz! (對不起,這麼晚回覆) – Maruen

相關問題