Created
June 3, 2015 21:15
-
-
Save r17171709/12e7d5652c9fba1a9cff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//动态刷新fragment的方法 | |
//将FragmentTransaction中的fragment全部清除 | |
public void addFragment() { | |
if(fragment_list != null){ | |
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
for(Fragment f: fragment_list){ | |
ft.remove(f); | |
} | |
ft.commitAllowingStateLoss(); | |
ft=null; | |
getSupportFragmentManager().executePendingTransactions(); | |
} | |
fragment_list.clear(); | |
Fragment1 f1=new Fragment1(); | |
f1.setOnJumpListener(new OnJumpListener() { | |
@Override | |
public void jumpToDetail() { | |
// TODO Auto-generated method stub | |
home_pager.setCurrentItem(1, true); | |
} | |
}); | |
fragment_list.add(f1); | |
fragment_list.add(new Fragment2()); | |
} | |
//刷新 | |
adapter.notifyDataSetChanged(); | |
//同样可以在adapter里面这边使用 | |
public void setFragments(ArrayList<Fragment> fragments) { | |
if(this.fragment_list != null){ | |
FragmentTransaction ft = fm.beginTransaction(); | |
for(Fragment f:this.fragment_list){ | |
ft.remove(f); | |
} | |
ft.commit(); | |
ft=null; | |
fm.executePendingTransactions(); | |
} | |
this.fragment_list = fragments; | |
notifyDataSetChanged(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment