2014-03-26 37 views

回答

0

我會回答我的問題。

您的活動實現了接口在DialogFragment定義

public void onCreateMatchDialogPositiveClick(DialogFragment dialog , String itemsToAdd) { 
      //Your Fragment Class containing listview to be updated 
     MyListViewFragmentClass fragment = (MyListViewFragmentClass) getSupportFragmentManager().findFragmentById(R.id.myListview); 

     if(fragment != null){ 
        //fragment is available 
      fragment.addItemToListView(itemsToAdd); 
     } 

    } 

然後在含有列表視圖中添加動態項目的片段

public void addItemToListView(itemToAdd){ 
     matchList.add(itemToAdd); //Add item to your dataset 
     adapter.notifyDataSetChanged();//Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh 
} 
+0

您可以發佈兩個類的完整代碼?我被困在相同的情況 –

+0

這裏是關於同樣情況的好文章:https://wuyingren.github.io/howto/2013/08/23/Updating-a-ListView-inside-a-Fragment-placed-on-一個-ViewPager-ON-DialogFragment-解僱/ – Amir