Lab 5
Lab 5
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#F6F0F0"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F6F0F0"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp"
android:text="Registration Page"
android:background="#F5F1F6"
android:textSize="40dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USERNAME:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp"/>
<EditText
android:id="@+id/userName"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="20dp"
android:inputType="text"
android:hint="Enter Username.."
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PASSWORD:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/passWord"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="20dp"
android:hint="Enter Password:"
android:inputType="textPassword"
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONFIRM PASSWORD:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/confirmPassword"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="20dp"
android:hint="Confirm Password:"
android:inputType="textPassword"
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/firstName"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="20dp"
android:hint="Enter First Name:"
android:inputType="text"
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/lastName"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="20dp"
android:hint="Enter First Name:"
android:inputType="text"
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email Address:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/eMail"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="20dp"
android:hint="Enter Email Address:"
android:inputType="text"
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Birthdate:"
android:textSize="20dp"
android:textStyle="bold" />
<DatePicker
android:id="@+id/datePickerDOB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
</LinearLayout>
<RadioGroup
android:id="@+id/radioGroupGender"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="35dp"
android:text="Gender"
android:textSize="20dp" />
<RadioButton
android:id="@+id/Male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Male"
android:textSize="20dp" />
<RadioButton
android:id="@+id/Female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Female"
android:textSize="20dp" />
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADDRESS:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="20dp"
android:hint="Enter Address:"
android:inputType="text"
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONTACT NUMBER:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp" />
<EditText
android:id="@+id/contactNumber"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="20dp"
android:hint="Enter Contact Number:"
android:inputType="text"
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hobbies:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp" />
<CheckBox
android:id="@+id/checkBoxReading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reading"
android:textSize="18dp" />
<CheckBox
android:id="@+id/checkBoxTraveling"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Traveling"
android:textSize="18dp" />
<CheckBox
android:id="@+id/checkBoxSports"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sports"
android:textSize="18dp" />
<CheckBox
android:id="@+id/checkBoxCooking"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cooking"
android:textSize="18dp" />
<CheckBox
android:id="@+id/checkBoxMusic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Music"
android:textSize="18dp" />
<CheckBox
android:id="@+id/checkBoxGardening"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gardening"
android:textSize="18dp" />
<CheckBox
android:id="@+id/checkBoxPhotography"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Photography"
android:textSize="18dp" />
<CheckBox
android:id="@+id/checkBoxArt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Art"
android:textSize="18dp" />
<CheckBox
android:id="@+id/checkBoxCoding"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coding"
android:textSize="18dp" />
<CheckBox
android:id="@+id/checkBoxDancing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dancing"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Security Questions:"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginLeft="5dp" />
<Spinner
android:id="@+id/securityQuestion1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"/>
<Spinner
android:id="@+id/securityQuestion2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"/>
<Spinner
android:id="@+id/securityQuestion3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"/>
</LinearLayout>
<Button
android:id="@+id/registerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBMIT"
android:layout_gravity="center"
android:layout_marginTop="20dp"/>
</LinearLayout>
</ScrollView>
package com.example.labexercise5;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Calendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize UI components
userName = findViewById(R.id.userName);
password = findViewById(R.id.passWord);
confirmPassword = findViewById(R.id.confirmPassword);
firstName = findViewById(R.id.firstName);
lastName = findViewById(R.id.lastName);
email = findViewById(R.id.eMail);
address = findViewById(R.id.address);
contactNumber = findViewById(R.id.contactNumber);
datePickerDOB = findViewById(R.id.datePickerDOB);
radioGroupGender = findViewById(R.id.radioGroupGender);
radioButtonMale = findViewById(R.id.Male);
radioButtonFemale = findViewById(R.id.Female);
securityQuestion1 = findViewById(R.id.securityQuestion1);
securityQuestion2 = findViewById(R.id.securityQuestion2);
securityQuestion3 = findViewById(R.id.securityQuestion3);
registerButton = findViewById(R.id.registerButton);
securityQuestionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dro
pdown_item);
securityQuestion1.setAdapter(securityQuestionAdapter);
securityQuestion2.setAdapter(securityQuestionAdapter);
securityQuestion3.setAdapter(securityQuestionAdapter);
// Set up listeners
datePickerDOB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDatePickerDialog();
}
});
registerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerUser();
}
});
}