// 显示某个相册的照片列表Fragment; private void showPhotoPickerFragment(String albumName, List<PhotoInfo> list) { // 显示左边按钮; mTvLeftCancleBtn.setVisibility(View.VISIBLE); mTvLeftArrowBtn.setVisibility(View.VISIBLE); mTitleTextView.setText(albumName); FragmentTransaction transaction = mFragmentManager .beginTransaction() .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); // 替换当前的Fragment; if (!mPhotoPickerFragment.isAdded()) { // 先判断是否被add过,如果没有add过,直接add这个fragment; Bundle args = new Bundle(); // 这个每次进入前都要把文件夹照片列表发送给photopickfragment; PhotoList photoSerializable = new PhotoList(); photoSerializable.setList(list); args.putSerializable("list", photoSerializable); mPhotoPickerFragment.setArguments(args); transaction .hide(mPhotoFolderFragment) .add(R.id.fragment_container, mPhotoPickerFragment) .commit(); // 隐藏当前的fragment,add下一个到Activity中 } else { // 如果已经add过,隐藏这个fragment,并且显示下一个fragment; mPhotoPickerFragment.updateDataList(list); transaction .hide(mPhotoFolderFragment) .show(mPhotoPickerFragment) .commit(); // 隐藏当前的fragment,显示下一个 } mCurrentFragment = mPhotoPickerFragment; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.lp_activity_localphoto); setTitleView(); mFragmentManager = getSupportFragmentManager(); mPhotoFolderFragment = new AlbumFragment(); mPhotoPickerFragment = new PhotoPickerFragment(); mPhotoPickerFragment.setOnPhotoSelectClickListener(this); mContentResolver = getContentResolver(); mListImageInfo.clear(); mAlbumName = getIntent().getStringExtra("albumName"); new ImageLoadAsyncTask().execute(); }