Using PHP and MySQL in Android To Manage Records
Using PHP and MySQL in Android To Manage Records
STEPS:
12. Clcik Create new table. Name your table as tblSchedules. Type 5 for the number of columns. Click Create.
5
13. Create the following fields.
a. Make id as integer (3)
b. Click Index and select Primary Key. Click OK at the dialog.
c. Check A_I checkbox for Auto Increment.
d. Type course_code varchar(15).
e. Type course_title varchar(255).
f. Type course_schedule varchar(255).
g. Type course_instructor varchar(120).
h. Click Save.
14. Click Insert. Add the following sample records. Click Go.
15. Add the other sample records.
<?php
$host = "localhost";
//Here, use the details for your own database and user
$username = "id21888060_admin";
$password = "#HKScholars2024";
$database = "id21888060_dbhkscholars";
?>
<?php
$course_code = $_POST['course_code'];
$course_title = $_POST['course_title'];
$course_schedule = $_POST['course_schedule'];
$course_instructor = $_POST['course_instructor'];
$response = array();
function saveSchedule($scheduledetails) {
require './connect.php';
$query = "INSERT INTO tblschedules (course_code, course_title, course_schedule, course_instructor)
VALUES "
. "(:course_code, :course_title, :course_schedule, :course_instructor)";
$stmt = $pdo->prepare($query);
return $stmt->execute($scheduledetails);
}
28. Create a New File. Name it getschedules.php. Type the following PHP code. Click Save & Close.
<?php
$response = array();
if (!empty($success)) {
$response['success'] = "1";
$response['message'] = "Schedules fetched successfully!";
$response['details'] = $success;
echo json_encode($response);
} else {
$response['success'] = "0";
$response['message'] = "Failed to fetch schedules!";
echo json_encode($response);
}
function getSchedules() {
require './connect.php';
$array = array();
$stmt = $pdo->prepare("SELECT * FROM tblschedules");
$stmt->execute();
$array = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt = null;
return $array;
}
29. Create a New File. Name it register.php. Type the following PHP code. Click Save & Close.
<?php
$useremail = $_POST['useremail'];
$username = $_POST['username'];
$password = $_POST['password'];
$password1 = $_POST['password1'];
$response = array();
function registerUser($userdetails) {
require './connect.php';
$query = "INSERT INTO tblusers (useremail, username, password) VALUES "
. "(:useremail, :username, :password)";
$stmt = $pdo->prepare($query);
return $stmt->execute($userdetails);
}
function checkUserEmail($value) {
require './connect.php';
$stmt = $pdo->prepare("SELECT * FROM tblusers WHERE useremail = ? ");
$stmt->execute([$value]);
$array = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = null;
return !empty($array);
}
function checkUserName($value) {
require './connect.php';
$stmt = $pdo->prepare("SELECT * FROM tblusers WHERE username = ? ");
$stmt->execute([$value]);
$array = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = null;
return !empty($array);
}
30. Create a New File. Name it updateuserprofile.php. Type the following PHP code. Click Save & Close.
<?php
$useremail = $_POST['useremail'];
$username = $_POST['username'];
$password = $_POST['password'];
$password1 = $_POST['password1'];
$response = array();
?>
31. Create a New File. Name it validate.php. Type the following PHP code. Click Save & Close.
<?php
$useremail = $_POST['useremail'];
$password = $_POST['password'];
$response = array();
$userdetails = array(
'useremail' => $useremail,
'password' => md5($password)
);
if (!empty($success)) {
$response['success'] = "1";
$response['message'] = "Login successfully!";
$response['details'] = $success;
echo json_encode($response);
} else {
$response['success'] = "0";
$response['message'] = "Login failed. Please try again!";
echo json_encode($response);
}
function loginUser($userdetails) {
require './connect.php';
$array = array();
$stmt = $pdo->prepare("SELECT * FROM tblusers WHERE useremail = :useremail AND password =
:password");
$stmt->execute($userdetails);
$array = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = null;
return $array;
}
32. Create a New File. Name it viewprofile.php. Type the following PHP code. Click Save & Close.
<?php
$useremail = $_POST['useremail'];
$response = array();
$userdetails = array(
'useremail' => $useremail
);
if (!empty($success)) {
$response['success'] = "1";
$response['message'] = "User details retrieved successfully!";
$response['details'] = $success;
echo json_encode($response);
} else {
$response['success'] = "0";
$response['message'] = "Retrieving user details failed. Please try again!";
echo json_encode($response);
}
function searchUserDetails($userdetails) {
require './connect.php';
$array = array();
$stmt = $pdo->prepare("SELECT * FROM tblusers WHERE useremail = :useremail");
$stmt->execute($userdetails);
$array = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = null;
return $array;
}
33. After creating the APIs, you should have these PHP files.
37. Double-click the java MainActivity. Edit the existing codes. Add nav_profile, nav_show_schedules,
nav_add_schedule.
38. Double-click the java LoginActivity. Delete all existing codes. Type the following Java codes.
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
EditText tuseremail,tpassword;
Button blogin;
Context ctx;
RequestQueue rQueue;
SharedPreferences sh;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ctx = this;
if (useremail.isEmpty()) {
tuseremail.setError("Email is required");
tuseremail.requestFocus();
return;
}
if (password.isEmpty()) {
tpassword.setError("Password is required");
tpassword.requestFocus();
return;
}
if (useremail.length() >0 && password.length() > 0) {
rQueue = Volley.newRequestQueue(getApplicationContext());
if (jsonObject.optString("success").equals("1")) {
JSONObject jsonObject1 =
jsonObject.getJSONObject("details");
Toast.makeText(LoginActivity.this, "Login
Successfully! ", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getBaseContext(),
MainActivity.class));
finish();
} else {
Toast.makeText(LoginActivity.this,
jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),
error.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("useremail", useremail);
params.put("password", password);
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Content-Type", "application/x-www-form-
urlencoded");
return params;
}
};
rQueue.add(stringRequest);
} else {
Toast.makeText(getApplicationContext(), "Please enter a valid email
and password", Toast.LENGTH_SHORT).show();
}
}
});
}
public void register(View v){
Intent i = new Intent(ctx, RegisterActivity.class);
startActivity(i);
}
}
39. Double-click the java RegisterActivity. Delete all existing codes. Type the following Java codes.
package <type your package name here>;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
tuseremail = findViewById(R.id.useremail);
tusername = findViewById(R.id.username);
tpassword = findViewById(R.id.password);
tpassword1 = findViewById(R.id.password1);
bregister = findViewById(R.id.register_btn);
bregister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String useremail = tuseremail.getText().toString();
final String username = tusername.getText().toString();
final String password = tpassword.getText().toString();
final String password1 = tpassword1.getText().toString();
if (useremail.isEmpty()) {
tuseremail.setError("Email is required");
tuseremail.requestFocus();
return;
}
if (username.isEmpty()) {
tusername.setError("Name is required");
tusername.requestFocus();
return;
}
if (password.isEmpty()) {
tpassword.setError("Password is required");
tpassword.requestFocus();
return;
}
if (password1.isEmpty()) {
tpassword1.setError("Very password is required");
tpassword1.requestFocus();
return;
}
if (!password1.equals(password)) {
tpassword1.setError("Very password is incorrect");
tpassword1.requestFocus();
return;
}
rQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST,
getResources().getString(R.string.url) + "register.php", new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.optString("success").equals("1")) {
Toast.makeText(RegisterActivity.this, "Registered
Successfully! Now Login", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getBaseContext(),
LoginActivity.class));
finish();
} else {
Toast.makeText(RegisterActivity.this,
jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(RegisterActivity.this, error.toString(),
Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("useremail", useremail);
params.put("username", username);
params.put("password", password);
params.put("password1", password1);
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Content-Type", "application/x-www-form-
urlencoded");
return params;
}
};
rQueue.add(stringRequest);
}
});
}
40. Create the java class ProfileFragment. Delete all existing codes. Type the following Java codes.
package <type your package name here>;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import androidx.fragment.app.Fragment;
public class ProfileFragment extends Fragment {
TextView tuseremail;
EditText tusername, tpassword, tpassword1;
Button bupdate;
Context ctx;
RequestQueue rQueue;
SharedPreferences sh;
public ProfileFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
sh = this.getActivity().getSharedPreferences("userdetail", Context.MODE_PRIVATE);
tuseremail = view.findViewById(R.id.useremail);
tusername = view.findViewById(R.id.username);
tpassword = view.findViewById(R.id.password);
tpassword1 = view.findViewById(R.id.password1);
tuseremail.setText(useremail);
tusername.setText(username);
tpassword.setText(password);
tpassword1.setText(password);
bupdate = view.findViewById(R.id.update_btn);
bupdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateProfile();
}
});
return view;
}
public void updateProfile(){
final String useremail = tuseremail.getText().toString();
final String username = tusername.getText().toString();
final String password = tpassword.getText().toString();
final String password1 = tpassword1.getText().toString();
if (useremail.isEmpty()) {
tuseremail.setError("Email is required");
tuseremail.requestFocus();
return;
}
if (username.isEmpty()) {
tusername.setError("Name is required");
tusername.requestFocus();
return;
}
if (password.isEmpty()) {
tpassword.setError("Password is required");
tpassword.requestFocus();
return;
}
if (password1.isEmpty()) {
tpassword1.setError("Very password is required");
tpassword1.requestFocus();
return;
}
if (!password1.equals(password)) {
tpassword1.setError("Very password is incorrect");
tpassword1.requestFocus();
return;
}
rQueue = Volley.newRequestQueue(getActivity().getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST,
getResources().getString(R.string.url) + "updateuserprofile.php", new
Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.optString("success").equals("1")) {
Toast.makeText(getActivity().getApplicationContext(), "User
profile updated successfully!", Toast.LENGTH_SHORT).show();
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
rQueue.add(stringRequest);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
}
@Override
public void onDetach() {
super.onDetach();
}
}
41. Create the java class Schedule. Delete all existing codes. Type the following Java codes.
package <type your package name here>;
public Schedule() {
}
42. Create the java class ScheduleAdapter. Delete all existing codes. Type the following Java codes.
package <type your package here>;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.PopupMenu;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.RecyclerView;
holder.course_code.setText(schedule.getCourseCode());
holder.course_title.setText(schedule.getCourseTitle());
holder.course_schedule.setText(schedule.getCourseSchedule());
holder.course_instructor.setText(schedule.getCourseInstructor());
holder.flowmenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu=new PopupMenu(v.getContext(), holder.flowmenu);
popupMenu.inflate(R.menu.flowmenu);
popupMenu.show();
Toast.makeText(v.getContext(), "Popup Menu: ",
Toast.LENGTH_SHORT).show();
popupMenu.setOnMenuItemClickListener(new
PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.edit_menu) {//edit operation
Bundle bundle = new Bundle();
bundle.putString("course_code", schedule.getCourseCode());
bundle.putString("course_title", schedule.getCourseTitle());
bundle.putString("course_schedule",
schedule.getCourseSchedule());
bundle.putString("course_instructor",
schedule.getCourseInstructor());
Intent intent = new Intent(v.getContext(),
EditScheduleFragment.class);
intent.putExtra("userdata", bundle);
v.getContext().startActivity(intent);
} else if (itemId == R.id.delete_menu) {
rQueue = Volley.newRequestQueue(v.getContext());
StringRequest stringRequest = new
StringRequest(Request.Method.POST, v.getContext().getResources().getString(R.string.url)
+ "deleteschedule.php", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.optString("success").equals("1"))
{
Toast.makeText(v.getContext(), "Schedule
deleted successfully!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(v.getContext(),
jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(v.getContext(), error.toString(),
Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String,
String>();
params.put("course_code", schedule.getCourseCode());
return params;
}
@Override
public Map<String, String> getHeaders() throws
AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Content-Type", "application/x-www-form-
urlencoded");
return params;
}
};
rQueue.add(stringRequest);
return false;
} else {
return false;
}
return true;
}
});
}
});
}
@Override
public int getItemCount() {
if (list != null) {
return list.size();
} else {
return 0;
}
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public final View view;
public final TextView course_code;
public final TextView course_title;
public final TextView course_schedule;
public final TextView course_instructor;
public final ImageView flowmenu;
public ViewHolder(View view) {
super(view);
this.view = view;
course_code = view.findViewById(R.id.course_code);
course_title = view.findViewById(R.id.course_title);
course_schedule = view.findViewById(R.id.course_schedule);
course_instructor = view.findViewById(R.id.course_instructor);
flowmenu = view.findViewById(R.id.flowmenu);
}
}
}
43. Create the java class SchedulesFragment. Delete all existing codes. Type the following Java codes.
package <type your package name here>;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public class SchedulesFragment extends Fragment {
private RecyclerView rv;
private RecyclerView.Adapter adapter;
RequestQueue rQueue;
ArrayList<Schedule> list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
list.add(new
Schedule(course_code,course_title,course_schedule,course_instructor));
}
adapter = new ScheduleAdapter(list);
rv.setAdapter(adapter);
} else {
Toast.makeText(getContext(),
jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(), error.toString(),
Toast.LENGTH_LONG).show();
}
});
rQueue = Volley.newRequestQueue(getContext());
rQueue.add(stringRequest);
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
}
@Override
public void onDetach() {
super.onDetach();
}
}
44. Create the java class AddScheduleFragment. Delete all existing codes. Type the following Java codes.
package <type your package name here>;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
public AddScheduleFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_add_schedule,container, false);
tcourse_code = view.findViewById(R.id.course_code);
tcourse_title = view.findViewById(R.id.course_title);
tcourse_schedule = view.findViewById(R.id.course_schedule);
tcourse_instructor = view.findViewById(R.id.course_instructor);
bsave = view.findViewById(R.id.save_btn);
bsave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String course_code = tcourse_code.getText().toString();
final String course_title = tcourse_title.getText().toString();
final String course_schedule = tcourse_schedule.getText().toString();
final String course_instructor = tcourse_instructor.getText().toString();
if (course_code.isEmpty()) {
tcourse_code.setError("Course code is required");
tcourse_code.requestFocus();
return;
}
if (course_title.isEmpty()) {
tcourse_title.setError("Course title is required");
tcourse_title.requestFocus();
return;
}
if (course_schedule.isEmpty()) {
tcourse_schedule.setError("Course schedule is required");
tcourse_schedule.requestFocus();
return;
}
if (course_instructor.isEmpty()) {
tcourse_instructor.setError("Course instructor is required");
tcourse_instructor.requestFocus();
return;
}
rQueue = Volley.newRequestQueue(getContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST,
getResources().getString(R.string.url) + "addschedule.php", new
Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.optString("success").equals("1")) {
Toast.makeText(getContext(), "New schedule added
successfully!", Toast.LENGTH_SHORT).show();
tcourse_code.setText("");
tcourse_title.setText("");
tcourse_schedule.setText("");
tcourse_instructor.setText("");
} else {
Toast.makeText(getContext(),
jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
tcourse_code.setText("");
tcourse_title.setText("");
tcourse_schedule.setText("");
tcourse_instructor.setText("");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(), error.toString(),
Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("course_code", course_code);
params.put("course_title", course_title);
params.put("course_schedule", course_schedule);
params.put("course_instructor", course_instructor);
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
rQueue.add(stringRequest);
}
});
return view;
}
}
45. Create layout for activity_login. Delete existing codes. Type the following codes.
<?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=".LoginActivity">
<ImageView
android:id="@+id/imageView5"
android:layout_width="155dp"
android:layout_height="142dp"
android:layout_marginTop="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<EditText
android:id="@+id/useremail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:ems="10"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/imageView5"
app:layout_constraintStart_toStartOf="@+id/imageView5"
app:layout_constraintTop_toBottomOf="@+id/imageView5" />
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:ems="10"
android:hint="Enter Password"
android:inputType="textPassword"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/useremail"
app:layout_constraintStart_toStartOf="@+id/useremail"
app:layout_constraintTop_toBottomOf="@+id/useremail" />
<Button
android:id="@+id/login_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="96dp"
android:onClick="login"
android:text="Login"
app:layout_constraintEnd_toEndOf="@+id/password"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="@+id/password"
app:layout_constraintTop_toBottomOf="@+id/password" />
<Button
android:id="@+id/register_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:onClick="register"
android:text="Register "
app:layout_constraintEnd_toEndOf="@+id/login_btn"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="@+id/login_btn"
app:layout_constraintTop_toBottomOf="@+id/login_btn" />
</androidx.constraintlayout.widget.ConstraintLayout>
46. Create layout for activity_register. Delete existing codes. Type the following codes.
<?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=".RegisterActivity">
<ImageView
android:id="@+id/imageView5"
android:layout_width="155dp"
android:layout_height="142dp"
android:layout_marginTop="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<EditText
android:id="@+id/useremail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:ems="10"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/imageView5"
app:layout_constraintStart_toStartOf="@+id/imageView5"
app:layout_constraintTop_toBottomOf="@+id/imageView5" />
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Enter User Name"
android:inputType="text"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/useremail"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/useremail"
app:layout_constraintTop_toBottomOf="@+id/useremail" />
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Enter Password"
android:inputType="textPassword"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/username"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/username"
app:layout_constraintTop_toBottomOf="@+id/username" />
<EditText
android:id="@+id/password1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:ems="10"
android:hint="Verify Password"
android:inputType="textPassword"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/password"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/password"
app:layout_constraintTop_toBottomOf="@+id/password" />
<Button
android:id="@+id/register_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:onClick="register"
android:text="Register "
app:layout_constraintEnd_toEndOf="@+id/password1"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="@+id/password1"
app:layout_constraintTop_toBottomOf="@+id/password1" />
<Button
android:id="@+id/login_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:onClick="login"
android:text="Login"
app:layout_constraintEnd_toEndOf="@+id/register_btn"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="@+id/register_btn"
app:layout_constraintTop_toBottomOf="@+id/register_btn" />
</androidx.constraintlayout.widget.ConstraintLayout>
47. Create layout for fragment_add_schedule. Delete existing codes. Type the following codes.
<?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=".AddScheduleFragment">
<ImageView
android:id="@+id/imageView5"
android:layout_width="155dp"
android:layout_height="142dp"
android:layout_marginTop="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<EditText
android:id="@+id/course_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:ems="10"
android:hint="Enter Course Code"
android:inputType="text"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/imageView5"
app:layout_constraintStart_toStartOf="@+id/imageView5"
app:layout_constraintTop_toBottomOf="@+id/imageView5" />
<EditText
android:id="@+id/course_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Enter Course Title"
android:inputType="text"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/course_code"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/course_code"
app:layout_constraintTop_toBottomOf="@+id/course_code" />
<EditText
android:id="@+id/course_schedule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Enter Course Schedule"
android:inputType="text"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/course_title"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/course_title"
app:layout_constraintTop_toBottomOf="@+id/course_title" />
<EditText
android:id="@+id/course_instructor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:ems="10"
android:hint="Enter Course Instructor"
android:inputType="text"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/course_schedule"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/course_schedule"
app:layout_constraintTop_toBottomOf="@+id/course_schedule" />
<Button
android:id="@+id/save_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:onClick="save"
android:text="Save"
app:layout_constraintEnd_toEndOf="@+id/course_instructor"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="@+id/course_instructor"
app:layout_constraintTop_toBottomOf="@+id/course_instructor" />
</androidx.constraintlayout.widget.ConstraintLayout>
48. Create layout for fragment_profile. Delete existing codes. Type the following codes.
<?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=".ProfileFragment">
<ImageView
android:id="@+id/imageView5"
android:layout_width="155dp"
android:layout_height="142dp"
android:layout_marginTop="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<EditText
android:id="@+id/useremail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:ems="10"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:minHeight="48dp"
android:enabled="false"
app:layout_constraintEnd_toEndOf="@+id/imageView5"
app:layout_constraintStart_toStartOf="@+id/imageView5"
app:layout_constraintTop_toBottomOf="@+id/imageView5" />
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Enter User Name"
android:inputType="text"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/useremail"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/useremail"
app:layout_constraintTop_toBottomOf="@+id/useremail" />
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Enter Password"
android:inputType="textPassword"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/username"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/username"
app:layout_constraintTop_toBottomOf="@+id/username" />
<EditText
android:id="@+id/password1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:ems="10"
android:hint="Verify Password"
android:inputType="textPassword"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="@+id/password"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/password"
app:layout_constraintTop_toBottomOf="@+id/password" />
<Button
android:id="@+id/update_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:text="Update"
app:layout_constraintEnd_toEndOf="@+id/password1"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="@+id/password1"
app:layout_constraintTop_toBottomOf="@+id/password1" />
</androidx.constraintlayout.widget.ConstraintLayout>
49. Create layout for fragment_schedules. Delete existing codes. Type the following codes.
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Schedules"
android:textAlignment="center"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/rvschedules"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvschedules"
android:layout_width="416dp"
android:layout_height="662dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5" />
</androidx.constraintlayout.widget.ConstraintLayout>
50. Create layout for schedule. Delete existing codes. Type the following codes.
<?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="100dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@color/material_dynamic_neutral95">
<ImageView
android:id="@+id/imageView6"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginBottom="2dp"
android:layout_marginStart="16dp"
android:layout_marginTop="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="32dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.666"
app:layout_constraintStart_toEndOf="@+id/imageView6"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lbl_course_code"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Code"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="@+id/course_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Code"
android:textSize="14dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lbl_course_title"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="@+id/course_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="14dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lbl_course_schedule"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Schedule"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="@+id/course_schedule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Schedule"
android:textSize="14dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lbl_course_instructor"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Instructor"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="@+id/course_instructor"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Instructor"
android:textSize="14dp" />
</TableRow>
</LinearLayout>
<ImageButton
android:id="@+id/flowmenu"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginBottom="36dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="32dp"
android:background="@null"
android:src="@drawable/baseline_more_vert_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias=".50"
app:layout_constraintStart_toEndOf="@+id/linearLayout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
51. Double-click menu activity_main_drawer. Add the following (green colored code):
<group android:checkableBehavior="single">
...
<item
android:id="@+id/nav_profile"
android:icon="@drawable/ic_menu_camera"
android:title="@string/menu_profile" />
</group>
<item android:title= "Schedules" >
<menu>
<item
android:id="@+id/nav_show_schedules"
android:icon="@drawable/ic_menu_camera"
android:title="@string/menu_show_schedules" />
<item
android:id= "@+id/nav_add_schedule"
android:icon= "@drawable/ic_menu_camera"
android:title= "@string/menu_add_schedule" />
</menu>
</item>
</menu>
52. Create a menu. Name it flowmenu.xml. Delete existing codes. Type the following codes.
53. Double-click the navigation mobile_navigation.xml. Add the following codes (green colored code).
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mobile_navigation"
app:startDestination="@id/nav_home">
...
<fragment
android:id="@+id/nav_profile"
android:name="com.hktracker.ProfileFragment"
android:label="@string/menu_profile" />
<fragment
android:id="@+id/nav_show_schedules"
android:name="com.hktracker.SchedulesFragment"
android:label="@string/menu_show_schedules" />
<fragment
android:id="@+id/nav_add_schedule"
android:name="com.hktracker.AddScheduleFragment"
android:label="@string/menu_add_schedule" />
</navigation>
54. Double-click the values strings.xml. Add the following codes (green colored codes):
<resources>
...
<string name="menu_profile">Profile</string>
<string name="menu_show_schedules">Show Schedules</string>
<string name="menu_add_schedule">Add Schedule</string>
<string name="url">https:/auhkscholarshub.000webhostapp.com/</string>
<string name="nav_open">Open</string>
<string name="nav_close">Close</string>
</resources>
Screenshots: