Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
Total Marks: 4
Obtained Marks:
Android Application
Development
Assignment # 02
Last date of Submission: 28th Oct 2022 (11:59 pm)
Submitted To: Qanetah Ahmed
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Student Name: Abrar Mubarik
______________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Reg. Number: 2012102
______________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
Instructions:
● Late submissions are not entertained in any case.
● Plagiarism will not be tolerated.
Question#1: (4 Marks)
By applying the concepts taught in class, you are to implement a Sign-Up and Login form in
Android Studio using Fragments. You will have the following files in your project:
1. [Link] + layout file (UI)
2. [Link] + layout file (UI)
3. [Link]+ layout file (UI)
In the main activity layout file you will place two buttons (B1, B2) and keep the rest space empty
for Fragment swapping/replacement.
If B1 is clicked LoginFragment will pop up & if B2 is clicked SignupFragment will replace
LoginFragment.
B1 B2
If B1 is clicked
LoginFragment
here.
If B2 is clicked
SignupFragment
here.
Submission guidelines:
You are to submit your code and output screenshots in a word document (in the form of a
report). Submit project file (code) as-well but zipped. Do not include report in project zip file.
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
Code:
XML:
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/b1"
android:layout_above="@id/b2"
android:layout_margin="8dp"
android:background="#EDEDED"
tools:ignore="NotSibling">
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Login"
android:textAlignment="center"
tools:ignore="MissingConstraints" />
</FrameLayout>
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/b1"
android:text="Signup"
tools:ignore="MissingConstraints,NotSibling" />
</[Link]>
Code:
package [Link].assingment2;
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Button loginButton = findViewById([Link].b1);
Button signupButton = findViewById([Link].b2);
[Link](new [Link]() {
@Override
public void onClick(View view) {
getSupportFragmentManager().beginTransaction()
.replace([Link].fragment_container, new
LoginFragment())
.commit();
}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
getSupportFragmentManager().beginTransaction()
.replace([Link].fragment_container, new
SignupFragment())
.commit();
}
});
}
}
package [Link].assingment2;
import [Link];
public class SignupFragment extends Fragment {
}
package [Link].assingment2;
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
import [Link];
public class LoginFragment extends Fragment {
}
Output: