There are three pages inherited from Fragment
And in one of them 2 more fragments are created.
public class Info extends TabFragment { private ExpandableListAdapter listAdapter; private ExpandableListView expListView; private List<String> listDataHeader; private HashMap<String, List<String>> listDataChild; private List<CityInfo> cityinfo; private TabLayout tabLayout; private FragmentActivity mycontext; @Override public void onAttach(Context context) { mycontext = (FragmentActivity) context; super.onAttach(context); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); try{ FragmentManager fm = ((FragmentActivity)view.getContext()).getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.simpleFrameLayout, new ListCity(cityinfo)); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); } catch (Exception e) { e.printStackTrace(); } } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { cityinfo = InternetConnect.getCityInfo(); View view = inflater.inflate(R.layout.maps_city, container, false); FrameLayout _simpleFrameLayout = (FrameLayout) view.findViewById(R.id.simpleFrameLayout); tabLayout = (TabLayout) view.findViewById(R.id.simpleTabLayout); tabLayout.getTabAt(0).setCustomView(R.layout.tab_element_layout); ((TextView) tabLayout.getTabAt(0).getCustomView().findViewById(R.id.TabMenu)).setText("СПИСОК"); tabLayout.getTabAt(1).setCustomView(R.layout.tab_element_layout); TextView tv = ((TextView) tabLayout.getTabAt(1).getCustomView().findViewById(R.id.TabMenu)); tv.setText("КАРТА"); Typeface tf = Typeface.createFromAsset(mycontext.getAssets(), getString(R.string.digit_keyboard_font)); tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { Fragment fragment = null; switch (tab.getPosition()) { case 1: fragment = new MapsActivity(cityinfo); break; case 0: fragment = new ListCity(cityinfo); break; } FragmentManager fm = mycontext.getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.simpleFrameLayout, fragment); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); return view; } }
When moving through fragments, an error quickly flies.
Process: com.example.myapplication, PID: 28641 java.lang.IllegalArgumentException: No view found for id 0x7f100110 (com.example.myapplication:id/simpleFrameLayout) for fragment ListCity{294f7a4f #2 id=0x7f100110} at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1293) If you remove these lines, the error disappears, but when you move to the desired fragment, it is empty.
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); try{ FragmentManager fm = ((FragmentActivity)view.getContext()).getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.simpleFrameLayout, new ListCity(cityinfo)); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); } catch (Exception e) { e.printStackTrace(); } } <android.support.design.widget.TabLayout android:id="@+id/simpleTabLayout" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabBackground="@color/white" app:tabGravity="center" android:theme="@style/TabItem" > <android.support.design.widget.TabItem android:layout_width="match_parent" android:layout_height="match_parent" android:text="СПИСОК" style="@style/TabItem" android:layout_margin="50dp" /> <android.support.design.widget.TabItem android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="КАРТА" android:padding="50dp" /> </android.support.design.widget.TabLayout> <FrameLayout android:id="@+id/simpleFrameLayout" android:layout_width="match_parent" android:layout_height="match_parent"></FrameLayout>
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);- Yuriy SPb ♦