Hello! Android is new. I would like to write an application for various schedules, primarily for schoolchildren and students. The application, according to my idea, consists of NavigationDrawer with the following tabs: Schedule, Grades, Examinations (and tests) and Tasks. In the tab with the schedule should be TabLayout with the days of the week. The essence of the question is as follows: in its implementation, NavigationDrawer should work with fragments (as I understand Google’s idea) so that it (NavigationDrawer) is accessible throughout the application, with NavigationDrawer Activities disappears. Duck here, How can I implement the structure described above? I tried to create a fragment with tabs, when I click on the day of the week, a fragment appears with the day of the week, but this approach seems to me to be incorrect, because when the application is started, the fragments work fine, but if you go to NavigationDrawer, for example, Evaluations and then return to the Schedule, then the fragments do not display anything and the tabs do not switch correctly, i.e. at what distance he ran his finger, so much taba and moved, while the information on it was zero. If you manually click on the last or the penultimate taboo, then information appears there and then the tabs normally begin to work. What to do in this situation, I do not know. Googling especially did nothing. Almost everywhere TabLayout is implemented inside the Activity, and not in the fragment. And in this case, the tabs will be in all fragments. Or is there any way to combine tabs, activity and NavigationDrawer? and how can you, when calling a fragment, remove tabs if they are organized at the activity level?
1 answer
You can set the container for the main activity
<FrameLayout android:id="@+id/frame_container" android:layout_width="match_parent" android:layout_height="match_parent" </RelativeLayout> And call the fragments out of necessity using
getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, new Fragment()).addToBackStack("tag").commit(); also in oncreate indicate the start of the fragment
- My NavigationDrawer and its menu items are initialized in MainActivity, that is, when I start, I launch a fragment with tabs, which in turn contain fragments from the days of the week. that is, onCreate (MainActivity) prescribed
ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.container, daysFragment); ft.commit();ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.container, daysFragment); ft.commit();thereby causing the same fragment with tabs - vaseel1ch - @ vaseel1ch, yes - djo
- that is, what I described in the question, my implementation, is it considered correct? that I created TabLayout in the fragment with a ViewPager, and this TabLayout contains other fragments - vaseel1ch
- @ vaseel1ch, you can call as many fragments as you like inside a fragment, you can also overlay one fragment onto another using .add () you can read it here - djo
|