0% found this document useful (0 votes)
28 views

Assignment#2 (Mobile Application Development) - 1

This document contains an assignment submission for a mobile application development class. The assignment required students to develop a sign-up form using various views like text, edit text, checkboxes and radio buttons. The document includes the XML code for the layout of the sign-up form and Java code to handle form submission. It provides the names of three students who submitted the assignment, along with details of the requirements and code submitted.

Uploaded by

ahmad imran
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)
28 views

Assignment#2 (Mobile Application Development) - 1

This document contains an assignment submission for a mobile application development class. The assignment required students to develop a sign-up form using various views like text, edit text, checkboxes and radio buttons. The document includes the XML code for the layout of the sign-up form and Java code to handle form submission. It provides the names of three students who submitted the assignment, along with details of the requirements and code submitted.

Uploaded by

ahmad imran
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/ 19

Assignment#1

Name Raza Ali


Hanan Ali
Ali Raza
Class BS Information Technology
Roll # 2753221
2753237
2753220
Subject Mobile Application Development

Submitted To:
Sir Afzaal Hussain
Requirement: Develop a Sign-Up Form. You are required to use
view as discussed in the class and listed below.
 Text View
 Edit Text
 Checkbox
 Radio Button
 Data Picker
 Button

XML Code:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
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"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Signup Form"
android:textSize="20dp"
/>
<View
android:layout_width="400dp"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_marginTop="2dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name:
android:textSize="15dp"/>
<EditText
android:id="@+id/userName"
android:layout_width="300dp"
android:layout_height="45dp"
android:textSize="15dp"
android:hint="Enter Username"
"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Email:
android:textSize="15dp""/>
<EditText
android:id="@+id/emaill"
android:layout_width="300dp"
android:layout_height="42dp"
android:textSize="15dp"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
android:textSize="15dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/userPassword"
android:layout_width="300dp"
android:layout_height="45dp"
android:textSize="15dp"
android:hint="Enter Password"
android:layout_marginLeft="13dp"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Confirm Password:"
android:textSize="15dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/confirmpassword"
android:layout_width="300dp"
android:layout_height="45dp"
android:textSize="15dp"
android:hint="confirm Password"
android:layout_marginLeft="13dp"
android:inputType="textPassword" />
</LinearLayout>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender”
android:textSize="15dp"
<RadioButton
android:id="@+id/Male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:gravity="center"
android:textSize="15dp"/>
<RadioButton
android:id="@+id/Female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:gravity="center"
android:textSize="15dp"/>
</RadioGroup>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:text="Sports"
<CheckBox
android:id="@+id/cricket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cricket"
android:textSize="15dp"/>
<CheckBox
android:id="@+id/hockey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hockey"
android:textSize="15dp"/>
<CheckBox
android:id="@+id/football"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Football"
android:textSize="15dp"/>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date Of Birth"
android:textSize="15dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/userDOB"
android:layout_width="300dp"
android:layout_height="45dp"
android:textSize="15dp"
android:hint="00/00/00"
android:layout_marginLeft="10dp"
android:inputType="number" />

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Country"
android:textSize="15dp"
android:layout_marginLeft="5dp"/>
<Spinner
android:id="@+id/SpCountry"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:textSize="30dp"/>
</LinearLayout>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Skills"
android:textSize="15dp"
<RadioButton
android:id="@+id/beginner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beginner"
android:gravity="center"
android:textSize="15dp"/>
<RadioButton
android:id="@+id/Advance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Advance"
android:gravity="center"
android:textSize="15dp"/>
</RadioGroup>
<CheckBox
android:id="@+id/agree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I accept the terms and conditions"
android:textSize="15dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btnSubmit"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="Click To Submit"
android:layout_marginTop="50dp"/>
<Button
android:id="@+id/btnClear"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="Click To Clear"
android:layout_marginTop="50dp"/>
</LinearLayout>
</LinearLayout>

Java Code:
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


EditText userName;
Button btnClear;

Spinner sp;
boolean invalid = false;
String Colector="";
TextView txtalertName;
EditText UserName,emaill,userPassword,confirmpassword,userDOB;
Button SubmitSave;
RadioButton beginner,Advance;
RadioButton Male,Female;
CheckBox agree;
CheckBox Cricket,Hockey,Football;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp=findViewById(R.id.SpCountry);
UserName=findViewById(R.id.userName);
beginner=findViewById(R.id.beginner);
Advance=findViewById(R.id.Advance);
userDOB=findViewById(R.id.userDOB);
agree=findViewById(R.id.agree);
emaill=findViewById(R.id.emaill);
userPassword=(EditText) findViewById(R.id.userPassword);
confirmpassword=(EditText) findViewById(R.id.confirmpassword);
Male =findViewById(R.id.Male);
Female=findViewById(R.id.Female);
Cricket=findViewById(R.id.cricket);
Hockey=findViewById(R.id.hockey);
Football=findViewById(R.id.football);
SubmitSave=findViewById(R.id.btnSubmit);
SubmitSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = UserName.getText().toString();
String email=emaill.getText().toString();
String password=userPassword.getText().toString();
String confirm=confirmpassword.getText().toString();
Log.d("testing", "userPassword: "+password);
Log.d("testing", "confirmpassword: "+confirm);
if (name.isEmpty()){
Toast.makeText(MainActivity.this,"Pleas fill the Name
field",Toast.LENGTH_SHORT).show();
}

else if (name.equals("gul") ||name.equals("fraz")){


invalid=true;
txtalertName.setText("Name Already exist");
}

else if(email.isEmpty()){
Toast.makeText(MainActivity.this,"Pleas fill the email
field",Toast.LENGTH_SHORT).show();
}
else if (password.isEmpty()){
Toast.makeText(MainActivity.this,"Pleas fill the Password
field",Toast.LENGTH_SHORT).show();
}

else if (confirm.isEmpty()){
Toast.makeText(MainActivity.this,"Pleas fill the Confirm
Password field",Toast.LENGTH_SHORT).show();
}
else{
if (!password.equals(confirm)) {
Toast.makeText(MainActivity.this,"password does not
match!!",Toast.LENGTH_SHORT).show();
}else{
Colector+=name+"\n";
Colector+=email+"\n";
Colector+=password+"\n";
Colector+=confirm+"\n";
if (Cricket.isChecked()){
Colector+="Cricket"+"\n";
if (Hockey.isChecked()){
Colector+="Hockey"+"\n";
}
if (Football.isChecked()){
Colector+="Football"+"\n";
}
}
Toast.makeText(MainActivity.this,"User Info \
n:"+Colector,Toast.LENGTH_SHORT).show();
}

}
});
userName=findViewById(R.id.userName);
emaill=findViewById(R.id.emaill);
userPassword.findViewById(R.id.userPassword);
confirmpassword.findViewById(R.id.confirmpassword);
Cricket.findViewById(R.id.cricket);
Male.findViewById(R.id.Male);
agree.findViewById(R.id.agree);
beginner.findViewById(R.id.beginner);
userDOB.findViewById(R.id.userDOB);
btnClear=findViewById(R.id.btnClear);
btnClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
userName.getText().clear();
emaill.getText().clear();
userPassword.getText().clear();
confirmpassword.getText().clear();
userDOB.getText().clear();

}
});

List<String> categoryCountry=new ArrayList<>();


categoryCountry.add("Select Country");
categoryCountry.add("PAKISTAN");
categoryCountry.add("AFGHANISTAN");
categoryCountry.add("UAE");
categoryCountry.add("TURKEY");
categoryCountry.add("AMERICA");
ArrayAdapter<String> arrayAdapter;
arrayAdapter=new
ArrayAdapter<>(this,android.R.layout.simple_spinner_item,categoryCountry
);

arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_
dropdown_item);
sp.setAdapter(arrayAdapter);
sp.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int
position, long l) {
if(parent.getItemAtPosition(position).equals("Select Country")){
//Do Nothing

}
else{
String item=parent.getItemAtPosition(position).toString();
Colector+=item+"\n";
Toast.makeText(MainActivity.this, "Selected Country: "+item,
Toast.LENGTH_SHORT).show();
}
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});
}
}

You might also like