0% found this document useful (0 votes)
41 views5 pages

Assignment 2

The document describes an Android application development assignment asking students to implement a sign-up and login form using fragments. It provides instructions to create three Java files (MainActivity, LoginFragment, SignupFragment) and their corresponding layout files. The main activity layout should contain two buttons - one to display the login fragment and the other to display the signup fragment. Students need to submit the project code zipped along with screenshots in a Word report. Sample code is provided to demonstrate replacing fragments on button clicks in the main activity.

Uploaded by

oneplus1674
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views5 pages

Assignment 2

The document describes an Android application development assignment asking students to implement a sign-up and login form using fragments. It provides instructions to create three Java files (MainActivity, LoginFragment, SignupFragment) and their corresponding layout files. The main activity layout should contain two buttons - one to display the login fragment and the other to display the signup fragment. Students need to submit the project code zipped along with screenshots in a Word report. Sample code is provided to demonstrate replacing fragments on button clicks in the main activity.

Uploaded by

oneplus1674
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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. MainActivity.java + layout file (UI)


2. LoginFragment.java + layout file (UI)
3. SignupFragment.java+ 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"?>
<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: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" />

</androidx.constraintlayout.widget.ConstraintLayout>

Code:
package com.example.assingment2;
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button loginButton = findViewById(R.id.b1);
Button signupButton = findViewById(R.id.b2);

loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, new
LoginFragment())
.commit();
}
});

signupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, new
SignupFragment())
.commit();
}
});
}
}

package com.example.assingment2;

import androidx.fragment.app.Fragment;

public class SignupFragment extends Fragment {


}

package com.example.assingment2;
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

import androidx.fragment.app.Fragment;

public class LoginFragment extends Fragment {


}

Output:

You might also like