Note - Double Click to Copy Code Contact Us!

Attendance Management System

Tech Doubility
Attendance Management System


First, let's create the XML layout file activity_attendance_management.xml for the activity:

XML Code
  1. <!-- activity_attendance_management.xml -->
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical"
  7. android:padding="16dp"
  8. tools:context=".AttendanceManagementActivity">
  9.  
  10. <TextView
  11. android:id="@+id/course_name_text_view"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:textAppearance="?android:attr/textAppearanceMedium" />
  15.  
  16. <Button
  17. android:id="@+id/mark_present_button"
  18. android:layout_width="match_parent"
  19. android:layout_height="wrap_content"
  20. android:text="Mark Present" />
  21.  
  22. <Button
  23. android:id="@+id/mark_absent_button"
  24. android:layout_width="match_parent"
  25. android:layout_height="wrap_content"
  26. android:text="Mark Absent" />
  27.  
  28. <Button
  29. android:id="@+id/view_attendance_button"
  30. android:layout_width="match_parent"
  31. android:layout_height="wrap_content"
  32. android:text="View Attendance" />
  33.  
  34. </LinearLayout>
  35.  
Next, let's create the Java code for the activity:

JAVA Code
  1. import androidx.appcompat.app.AppCompatActivity;
  2. import android.os.Bundle;
  3. import android.view.View;
  4. import android.widget.Button;
  5. import android.widget.TextView;
  6. import android.widget.Toast;
  7.  
  8. public class AttendanceManagementActivity extends AppCompatActivity {
  9.  
  10. private TextView courseNameTextView;
  11. private Button markPresentButton;
  12. private Button markAbsentButton;
  13. private Button viewAttendanceButton;
  14.  
  15. private String courseName;
  16. private int presentCount;
  17. private int absentCount;
  18.  
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_attendance_management);
  23.  
  24. // Initialize views
  25. courseNameTextView = findViewById(R.id.course_name_text_view);
  26. markPresentButton = findViewById(R.id.mark_present_button);
  27. markAbsentButton = findViewById(R.id.mark_absent_button);
  28. viewAttendanceButton = findViewById(R.id.view_attendance_button);
  29.  
  30. // Initialize attendance data
  31. courseName = "Android Development";
  32. presentCount = 0;
  33. absentCount = 0;
  34.  
  35. // Set course name
  36. courseNameTextView.setText(courseName);
  37.  
  38. // Set mark present button click listener
  39. markPresentButton.setOnClickListener(new View.OnClickListener() {
  40. @Override
  41. public void onClick(View v) {
  42. markPresent();
  43. }
  44. });
  45.  
  46. // Set mark absent button click listener
  47. markAbsentButton.setOnClickListener(new View.OnClickListener() {
  48. @Override
  49. public void onClick(View v) {
  50. markAbsent();
  51. }
  52. });
  53.  
  54. // Set view attendance button click listener
  55. viewAttendanceButton.setOnClickListener(new View.OnClickListener() {
  56. @Override
  57. public void onClick(View v) {
  58. viewAttendance();
  59. }
  60. });
  61. }
  62.  
  63. private void markPresent() {
  64. presentCount++;
  65. Toast.makeText(this, "Attendance Marked Present", Toast.LENGTH_SHORT).show();
  66. }
  67.  
  68. private void markAbsent() {
  69. absentCount++;
  70. Toast.makeText(this, "Attendance Marked Absent", Toast.LENGTH_SHORT).show();
  71. }
  72.  
  73. private void viewAttendance() {
  74. String attendanceInfo = "Present: " + presentCount + "\nAbsent: " + absentCount;
  75. Toast.makeText(this, attendanceInfo, Toast.LENGTH_LONG).show();
  76. }
  77. }
  78.  
In this example, the AttendanceManagementActivity class extends AppCompatActivity.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.