Шаблон для разработки
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Merge core/template-android-project to this repo / merge-if-needed (push) Failing after 15s
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Merge core/template-android-project to this repo / merge-if-needed (push) Failing after 15s
				
			This commit is contained in:
		
							
								
								
									
										63
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,63 @@ | |||||||
|  | [](https://sicampus.ru/gitea/core/docs/src/branch/main/how-upload-project.md) | ||||||
|  |  | ||||||
|  | # Практическая работа. Курс Kotlin. Практическая 3.8 | ||||||
|  | Данная практическая работа направлена на реализацию переходов между фрагментами | ||||||
|  |  | ||||||
|  | ## Дополнение XML разметки | ||||||
|  | Первым делом необходимо дополнить разметку XML для корректного использования ссылок внутри Kotlin кода. Необходимые места для заполнения представлены ниже. | ||||||
|  |  | ||||||
|  | Реализовать фрагмент для навигации внутри файла *activity_main.xml*. Фрагмент должен растягиваться по родительскому объекту, иметь уникальный идентификатор `@+id/nav_host_fragment` и обозначить параметр navGraph равный `nav_graph` | ||||||
|  | ```xml | ||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:id="@+id/main" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent" | ||||||
|  |     tools:context=".MainActivity"> | ||||||
|  |  | ||||||
|  |     <!--  TODO: Реализовать здесь  --> | ||||||
|  |  | ||||||
|  | </androidx.constraintlayout.widget.ConstraintLayout> | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | Создать переход из третьего фрагмента в первый с уникальным идентификатором `@+id/action_thirdFragment_to_firstFragment` внутри файла *nav_graph.xml* | ||||||
|  | ```xml | ||||||
|  | ... | ||||||
|  | <fragment | ||||||
|  |     android:id="@+id/thirdFragment" | ||||||
|  |     android:name="ru.myitschool.work.ThirdFragment" | ||||||
|  |     android:label="Third Fragment"> | ||||||
|  |     <!--  TODO: Реализовать здесь  --> | ||||||
|  | </fragment> | ||||||
|  | ... | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ## Дополнение Kotlin кода | ||||||
|  | Далее необходимо написать дополнить код для взаимодействия с кнопками для перехода | ||||||
|  |  | ||||||
|  | FirstFragment.kt | ||||||
|  | ```kotlin | ||||||
|  | ... | ||||||
|  | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||||||
|  |     super.onViewCreated(view, savedInstanceState) | ||||||
|  |     val fromFirstToSecond: Button = view.findViewById(R.id.fromFirstToSecond) | ||||||
|  |     val fromFirstToThird: Button = view.findViewById(R.id.fromFirstToThird) | ||||||
|  |  | ||||||
|  |     // TODO: Создать переход при клике на кнопку с первого на второй фрагмент. Подробнее смотреть в файле навигации! | ||||||
|  |  | ||||||
|  |     // TODO: Создать переход при клике на кнопку с первого на третий фрагмент. Подробнее смотреть в файле навигации! | ||||||
|  | } | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ThirdFragment.kt | ||||||
|  | ```kotlin | ||||||
|  | ... | ||||||
|  | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||||||
|  |     super.onViewCreated(view, savedInstanceState) | ||||||
|  |     val fromThirdToFirst: Button = view.findViewById(R.id.fromThirdToFirst) | ||||||
|  |  | ||||||
|  |     // TODO: Создать переход при клике на кнопку с третьего на первый фрагмент. Подробнее смотреть в файле навигации! | ||||||
|  | } | ||||||
|  | ``` | ||||||
| @@ -1,4 +1,5 @@ | |||||||
| plugins { | plugins { | ||||||
|  |     id("org.jetbrains.kotlin.android") | ||||||
|     androidApplication |     androidApplication | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -24,8 +25,18 @@ android { | |||||||
|         sourceCompatibility = Version.Kotlin.javaSource |         sourceCompatibility = Version.Kotlin.javaSource | ||||||
|         targetCompatibility = Version.Kotlin.javaSource |         targetCompatibility = Version.Kotlin.javaSource | ||||||
|     } |     } | ||||||
|  |     kotlinOptions { | ||||||
|  |         jvmTarget = "17" | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|  |     implementation("androidx.appcompat:appcompat:1.7.0") | ||||||
|  |     implementation("com.google.android.material:material:1.12.0") | ||||||
|  |     implementation("androidx.activity:activity:1.9.1") | ||||||
|  |     implementation("androidx.constraintlayout:constraintlayout:2.1.4") | ||||||
|  |     implementation("androidx.navigation:navigation-fragment-ktx:2.7.7") | ||||||
|  |     implementation("androidx.navigation:navigation-ui-ktx:2.7.7") | ||||||
|  |     implementation("androidx.core:core-ktx:1.13.1") | ||||||
|     defaultLibrary() |     defaultLibrary() | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,7 +10,14 @@ | |||||||
|         android:label="@string/app_name" |         android:label="@string/app_name" | ||||||
|         android:roundIcon="@mipmap/ic_launcher_round" |         android:roundIcon="@mipmap/ic_launcher_round" | ||||||
|         android:supportsRtl="true" |         android:supportsRtl="true" | ||||||
|         android:theme="@style/Theme.Default" |         android:theme="@style/Theme.Design.Light.NoActionBar" | ||||||
|         tools:targetApi="31" /> |         tools:targetApi="31"> | ||||||
|  |         <activity android:name=".MainActivity" android:exported="true"> | ||||||
|  |             <intent-filter> | ||||||
|  |                 <action android:name="android.intent.action.MAIN" /> | ||||||
|  |                 <category android:name="android.intent.category.LAUNCHER" /> | ||||||
|  |             </intent-filter> | ||||||
|  |         </activity> | ||||||
|  |     </application> | ||||||
|  |  | ||||||
| </manifest> | </manifest> | ||||||
							
								
								
									
										29
									
								
								app/src/main/java/ru/myitschool/work/FirstFragment.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/src/main/java/ru/myitschool/work/FirstFragment.kt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | |||||||
|  | package ru.myitschool.work | ||||||
|  |  | ||||||
|  | import android.os.Bundle | ||||||
|  | import androidx.fragment.app.Fragment | ||||||
|  | import android.view.LayoutInflater | ||||||
|  | import android.view.View | ||||||
|  | import android.view.ViewGroup | ||||||
|  | import android.widget.Button | ||||||
|  | import androidx.navigation.fragment.findNavController | ||||||
|  |  | ||||||
|  | class FirstFragment : Fragment() { | ||||||
|  |  | ||||||
|  |     override fun onCreateView( | ||||||
|  |         inflater: LayoutInflater, container: ViewGroup?, | ||||||
|  |         savedInstanceState: Bundle? | ||||||
|  |     ): View? { | ||||||
|  |         return inflater.inflate(R.layout.fragment_first, container, false) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||||||
|  |         super.onViewCreated(view, savedInstanceState) | ||||||
|  |         val fromFirstToSecond: Button = view.findViewById(R.id.fromFirstToSecond) | ||||||
|  |         val fromFirstToThird: Button = view.findViewById(R.id.fromFirstToThird) | ||||||
|  |  | ||||||
|  |         // TODO: Создать переход при клике на кнопку с первого на второй фрагмент. Подробнее смотреть в файле навигации! | ||||||
|  |  | ||||||
|  |         // TODO: Создать переход при клике на кнопку с первого на третий фрагмент. Подробнее смотреть в файле навигации! | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								app/src/main/java/ru/myitschool/work/MainActivity.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								app/src/main/java/ru/myitschool/work/MainActivity.kt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | package ru.myitschool.work | ||||||
|  |  | ||||||
|  | import android.os.Bundle | ||||||
|  | import androidx.activity.enableEdgeToEdge | ||||||
|  | import androidx.appcompat.app.AppCompatActivity | ||||||
|  | import androidx.core.view.ViewCompat | ||||||
|  | import androidx.core.view.WindowInsetsCompat | ||||||
|  |  | ||||||
|  | class MainActivity : AppCompatActivity() { | ||||||
|  |     override fun onCreate(savedInstanceState: Bundle?) { | ||||||
|  |         super.onCreate(savedInstanceState) | ||||||
|  |         enableEdgeToEdge() | ||||||
|  |         setContentView(R.layout.activity_main) | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										17
									
								
								app/src/main/java/ru/myitschool/work/SecondFragment.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								app/src/main/java/ru/myitschool/work/SecondFragment.kt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | |||||||
|  | package ru.myitschool.work | ||||||
|  |  | ||||||
|  | import android.os.Bundle | ||||||
|  | import androidx.fragment.app.Fragment | ||||||
|  | import android.view.LayoutInflater | ||||||
|  | import android.view.View | ||||||
|  | import android.view.ViewGroup | ||||||
|  |  | ||||||
|  | class SecondFragment : Fragment() { | ||||||
|  |  | ||||||
|  |     override fun onCreateView( | ||||||
|  |         inflater: LayoutInflater, container: ViewGroup?, | ||||||
|  |         savedInstanceState: Bundle? | ||||||
|  |     ): View? { | ||||||
|  |         return inflater.inflate(R.layout.fragment_second, container, false) | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										26
									
								
								app/src/main/java/ru/myitschool/work/ThirdFragment.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/src/main/java/ru/myitschool/work/ThirdFragment.kt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | package ru.myitschool.work | ||||||
|  |  | ||||||
|  | import android.os.Bundle | ||||||
|  | import androidx.fragment.app.Fragment | ||||||
|  | import android.view.LayoutInflater | ||||||
|  | import android.view.View | ||||||
|  | import android.view.ViewGroup | ||||||
|  | import android.widget.Button | ||||||
|  | import androidx.navigation.fragment.findNavController | ||||||
|  |  | ||||||
|  | class ThirdFragment : Fragment() { | ||||||
|  |  | ||||||
|  |     override fun onCreateView( | ||||||
|  |         inflater: LayoutInflater, container: ViewGroup?, | ||||||
|  |         savedInstanceState: Bundle? | ||||||
|  |     ): View? { | ||||||
|  |         return inflater.inflate(R.layout.fragment_third, container, false) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||||||
|  |         super.onViewCreated(view, savedInstanceState) | ||||||
|  |         val fromThirdToFirst: Button = view.findViewById(R.id.fromThirdToFirst) | ||||||
|  |  | ||||||
|  |         // TODO: Создать переход при клике на кнопку с третьего на первый фрагмент. Подробнее смотреть в файле навигации! | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										12
									
								
								app/src/main/res/layout/activity_main.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/src/main/res/layout/activity_main.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:id="@+id/main" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent" | ||||||
|  |     tools:context=".MainActivity"> | ||||||
|  |  | ||||||
|  |     <!--  TODO: Реализовать фрагмент для навигации. Должен растягиваться по родительскому объекту, иметь id "nav_host_fragment" и обозначить параметр navGraph "nav_graph"  --> | ||||||
|  |  | ||||||
|  | </androidx.constraintlayout.widget.ConstraintLayout> | ||||||
							
								
								
									
										31
									
								
								app/src/main/res/layout/fragment_first.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								app/src/main/res/layout/fragment_first.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent" | ||||||
|  |     tools:context=".FirstFragment"> | ||||||
|  |  | ||||||
|  |     <TextView | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:text="First Fragment" | ||||||
|  |         android:layout_gravity="center" /> | ||||||
|  |  | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_gravity="bottom|center" | ||||||
|  |         android:orientation="vertical"> | ||||||
|  |         <Button | ||||||
|  |             android:id="@+id/fromFirstToSecond" | ||||||
|  |             android:layout_width="wrap_content" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:text="Second" /> | ||||||
|  |         <Button | ||||||
|  |             android:id="@+id/fromFirstToThird" | ||||||
|  |             android:layout_width="wrap_content" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:text="Third" /> | ||||||
|  |     </LinearLayout> | ||||||
|  |  | ||||||
|  | </FrameLayout> | ||||||
							
								
								
									
										14
									
								
								app/src/main/res/layout/fragment_second.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								app/src/main/res/layout/fragment_second.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent" | ||||||
|  |     tools:context=".SecondFragment"> | ||||||
|  |  | ||||||
|  |     <TextView | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:text="Second Fragment" | ||||||
|  |         android:layout_gravity="center" /> | ||||||
|  |  | ||||||
|  | </FrameLayout> | ||||||
							
								
								
									
										26
									
								
								app/src/main/res/layout/fragment_third.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/src/main/res/layout/fragment_third.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent" | ||||||
|  |     tools:context=".ThirdFragment"> | ||||||
|  |  | ||||||
|  |     <TextView | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:text="Third Fragment" | ||||||
|  |         android:layout_gravity="center" /> | ||||||
|  |  | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_gravity="bottom|center" | ||||||
|  |         android:orientation="vertical"> | ||||||
|  |         <Button | ||||||
|  |             android:id="@+id/fromThirdToFirst" | ||||||
|  |             android:layout_width="wrap_content" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:text="Second" /> | ||||||
|  |     </LinearLayout> | ||||||
|  |  | ||||||
|  | </FrameLayout> | ||||||
							
								
								
									
										29
									
								
								app/src/main/res/navigation/nav_graph.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/src/main/res/navigation/nav_graph.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <navigation xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|  |     android:id="@+id/nav_graph" | ||||||
|  |     app:startDestination="@id/firstFragment"> | ||||||
|  |     <fragment | ||||||
|  |         android:id="@+id/firstFragment" | ||||||
|  |         android:name="ru.myitschool.work.FirstFragment" | ||||||
|  |         android:label="First Fragment"> | ||||||
|  |         <action | ||||||
|  |             android:id="@+id/action_firstFragment_to_secondFragment" | ||||||
|  |             app:destination="@id/secondFragment" /> | ||||||
|  |         <action | ||||||
|  |             android:id="@+id/action_firstFragment_to_thirdFragment" | ||||||
|  |             app:destination="@id/thirdFragment" /> | ||||||
|  |     </fragment> | ||||||
|  |  | ||||||
|  |     <fragment | ||||||
|  |         android:id="@+id/secondFragment" | ||||||
|  |         android:name="ru.myitschool.work.SecondFragment" | ||||||
|  |         android:label="Second Fragment"/> | ||||||
|  |  | ||||||
|  |     <fragment | ||||||
|  |         android:id="@+id/thirdFragment" | ||||||
|  |         android:name="ru.myitschool.work.ThirdFragment" | ||||||
|  |         android:label="Third Fragment"> | ||||||
|  |     <!--  TODO: Создать переход из третьего фрагмента в первый с id "action_thirdFragment_to_firstFragment"  --> | ||||||
|  |     </fragment> | ||||||
|  | </navigation> | ||||||
| @@ -1,3 +1,4 @@ | |||||||
| <resources> | <resources> | ||||||
|     <string name="app_name">Work</string> |     <string name="app_name">Work</string> | ||||||
|  |     <string name="hello_blank_fragment">Hello blank fragment</string> | ||||||
| </resources> | </resources> | ||||||
| @@ -5,7 +5,7 @@ | |||||||
| --> | --> | ||||||
| <data-extraction-rules> | <data-extraction-rules> | ||||||
|     <cloud-backup> |     <cloud-backup> | ||||||
|         <!-- TODO: Use <include> and <exclude> to control what is backed up. |         <!-- | ||||||
|         <include .../> |         <include .../> | ||||||
|         <exclude .../> |         <exclude .../> | ||||||
|         --> |         --> | ||||||
|   | |||||||
| @@ -2,4 +2,5 @@ | |||||||
| plugins { | plugins { | ||||||
|     androidApplication version Version.gradle apply false |     androidApplication version Version.gradle apply false | ||||||
|     kotlinJvm version Version.Kotlin.language apply false |     kotlinJvm version Version.Kotlin.language apply false | ||||||
|  |     id("org.jetbrains.kotlin.android") version "2.0.0" apply false | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user