Mad Assignment 3
Mad Assignment 3
Education Lahore
Name:Zain Ali
Roll No : mtf24002743
Fragment 1.Kotlin
Fragment1.Xml
Fragment2.kotlin
Fragment2.xml
MainActivity.kotlin fragment
Intent:
An intent is like a messenger between different parts of your app.
It is used to start a new activity, start a service, or send information between
activities/fragments.
You use intents when you want to move from one screen to another or pass data.
Example:
In a login app :
After login, you want to open the home screen.
You create an Intent to move from LoginActivity ➔ HomeActivity.
Q 2 :How to create Fragment?
Open res folder -> right click layout file ->add blank fragment.
Name to fragment1.
Change Layout to relative layout.
Same for fragment2.
Implement Fragment class method for Fragment1
In Fragment1.kotlinfile:
Fragment1:Fragment()
class Fragment1:Fragment(R.layout.fragment1) {
}
In main Activity :
lateinit var binding:ActivityMainBinding
Q3What is Relative Laout?
RelativeLayout is a ViewGroup (a type of layout) where you can position child views relative
to each other or relative to the parent.
To the left, right, above, or below another view.
Align views to the parent’s top, bottom, left, or right.
Code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:layout_centerInParent="true" />
</RelativeLayout>
Q4 What is Android and androidx library?
Android Library
In Android development, a library is a collection of ready-made code, layouts, functions, etc.,
that you can reuse in your project.
Android libraries were originally provided by Google with the Android platform itself.
Examples include:
android.app.Activity
android.widget.Button
android.view.View
etc.
Androidx Library
if (viewType == 1) {
ItemOneBinding binding = ItemOneBinding.inflate(inflater, parent, false);
return new OneViewHolder(binding);
} else {
ItemTwoBinding binding = ItemTwoBinding.inflate(inflater, parent, false);
return new TwoViewHolder(binding);
}
}