먼저 문제/질문을 재현 해 보겠습니다.SectionsPageAdapter with FragmentPageAdapter
내 활동은 SectionPageAdapter 및 FragmentPageAdapter를 사용하여 3 탭이있는 TabbedActivity입니다.
이 3 개의 탭에서 사용자는 데이터를 입력합니다. 스 와이프 만하면 사용자가 탭을 변경할 수 있습니다. 사용자가 모든 데이터를 채운 후에는 FloatingActionButton을 클릭하여 데이터를 저장해야합니다.
이제 문제가 있습니다. 채워진 데이터로이 3 개의 조각에 액세스 할 수 있는지 모르겠습니까? 채워진 데이터로 3 개의 조각을 모두로드하고 데이터를 읽고 저장하거나 페이지를 변경하기 전에 PageChangeListenEvent를 처리하고 데이터를 저장해야합니까?
코드 :
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return TravelInfoActivity.PlaceholderFragment.newInstance(position + 1);
}
@Override
public int getCount() {
return maxTabs;
}
}
public static class PlaceholderFragment extends Fragment {
private static final String ARG_FRAGMENT_ID = "fragment_id";
private static int REQUEST_CODE_PLACE = 1;
private View currentRootView;
private View currentClickedView;
@SuppressLint("UseSparseArrays")
private HashMap<Integer, View> hMap = new HashMap<>();
public PlaceholderFragment() {
}
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static TravelInfoActivity.PlaceholderFragment newInstance(int sectionNumber) {
TravelInfoActivity.PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
int fragmentLayout;
switch (sectionNumber) {
case 1:
fragmentLayout = R.layout.fragment_accommodation;
break;
case 2:
fragmentLayout = R.layout.fragment_visited_places;
break;
case 3:
fragmentLayout = R.layout.fragment_additional_info;
break;
default:
fragmentLayout = R.layout.fragment_accommodation;
}
args.putInt(ARG_FRAGMENT_ID, fragmentLayout);
fragment.setArguments(args);
return fragment;
}
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View rootView = inflater.inflate(getArguments().getInt(ARG_FRAGMENT_ID), container, false);
currentRootView = rootView;
switch (getArguments().getInt(ARG_FRAGMENT_ID)) {
// switch handling here, not relevant
}
return rootView;
}