当前位置:   article > 正文

基于Android Studio 实现学生宿舍管理系统(可做毕设)--原创_android dormitorymanagementsystem

android dormitorymanagementsystem

目录

一、实现介绍

视频演示

1.1 启动页实现

1.2 注册页面实现

1.3 登陆页面实现

1.4 学生首页实现

 1.5 学生我的页面实现               

1.6 学生个人信息页面实现

1.7 管理员首页页面实现 

1.8 管理员我的页面实现

1.9 发布公告页面实现

1.10 添加学生页面实现     

Get 项目模板源码


一、实现介绍

视频演示

Android studio毕业设计~宿舍管理系统

1.1 启动页实现

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:background="#1C367E "
  8. tools:context=".UI_Public.StartActivity">
  9. <ImageView
  10. android:id="@+id/imageView"
  11. android:layout_width="0dp"
  12. android:layout_height="0dp"
  13. app:layout_constraintBottom_toBottomOf="parent"
  14. app:layout_constraintEnd_toEndOf="parent"
  15. app:layout_constraintStart_toStartOf="parent"
  16. app:layout_constraintTop_toTopOf="parent"
  17. app:srcCompat="@drawable/logo" />
  18. </androidx.constraintlayout.widget.ConstraintLayout>

1.2 注册页面实现

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:background="#FFFEFE"
  8. tools:context=".UI_Public.RegisterActivity">
  9. <View
  10. android:id="@+id/view"
  11. android:layout_width="wrap_content"
  12. android:layout_height="400dp"
  13. android:background="#1C367E"
  14. app:layout_constraintEnd_toEndOf="parent"
  15. app:layout_constraintStart_toStartOf="parent"
  16. app:layout_constraintTop_toTopOf="parent" />
  17. <ImageView
  18. android:id="@+id/imageView2"
  19. android:layout_width="0dp"
  20. android:layout_height="200dp"
  21. android:layout_marginTop="24dp"
  22. app:layout_constraintEnd_toEndOf="parent"
  23. app:layout_constraintStart_toStartOf="parent"
  24. app:layout_constraintTop_toTopOf="parent"
  25. app:srcCompat="@drawable/logo" />
  26. <LinearLayout
  27. android:id="@+id/linearLayout"
  28. android:layout_width="0dp"
  29. android:layout_height="wrap_content"
  30. android:layout_marginStart="32dp"
  31. android:layout_marginTop="8dp"
  32. android:layout_marginEnd="32dp"
  33. android:background="@drawable/view_lr"
  34. android:gravity="center|top"
  35. android:orientation="vertical"
  36. app:layout_constraintEnd_toEndOf="parent"
  37. app:layout_constraintStart_toStartOf="parent"
  38. app:layout_constraintTop_toBottomOf="@+id/imageView2">
  39. <LinearLayout
  40. android:layout_width="match_parent"
  41. android:layout_height="match_parent"
  42. android:layout_marginLeft="15dp"
  43. android:layout_marginTop="20dp"
  44. android:layout_marginRight="15dp"
  45. android:layout_marginBottom="20dp"
  46. android:orientation="vertical">
  47. <EditText
  48. android:id="@+id/et_name"
  49. android:layout_width="match_parent"
  50. android:layout_height="wrap_content"
  51. android:ems="10"
  52. android:hint="请输入姓名!"
  53. android:inputType="textPersonName"
  54. android:textSize="14sp" />
  55. <EditText
  56. android:id="@+id/et_num"
  57. android:layout_width="match_parent"
  58. android:layout_height="wrap_content"
  59. android:layout_marginTop="15dp"
  60. android:ems="10"
  61. android:hint="请输入学号!"
  62. android:inputType="textPersonName"
  63. android:textSize="14sp" />
  64. <EditText
  65. android:id="@+id/et_phone"
  66. android:layout_width="match_parent"
  67. android:layout_height="wrap_content"
  68. android:layout_marginTop="15dp"
  69. android:ems="10"
  70. android:hint="请输入电话号码!"
  71. android:inputType="phone"
  72. android:textSize="14sp" />
  73. <EditText
  74. android:id="@+id/et_pass"
  75. android:layout_width="match_parent"
  76. android:layout_height="wrap_content"
  77. android:layout_marginTop="15dp"
  78. android:ems="10"
  79. android:hint="请输入密码!"
  80. android:inputType="textPassword"
  81. android:textSize="14sp" />
  82. <EditText
  83. android:id="@+id/et_rpass"
  84. android:layout_width="match_parent"
  85. android:layout_height="wrap_content"
  86. android:layout_marginTop="15dp"
  87. android:ems="10"
  88. android:hint="请再次输入密码!"
  89. android:inputType="textPassword"
  90. android:textSize="14sp" />
  91. <LinearLayout
  92. android:layout_width="match_parent"
  93. android:layout_height="wrap_content"
  94. android:layout_marginTop="15dp"
  95. android:orientation="horizontal">
  96. <RadioGroup
  97. android:id="@+id/rg"
  98. android:layout_width="match_parent"
  99. android:layout_height="match_parent"
  100. android:gravity="center"
  101. android:orientation="horizontal">
  102. <RadioButton
  103. android:id="@+id/rb_man"
  104. android:layout_width="wrap_content"
  105. android:layout_height="wrap_content"
  106. android:checked="true"
  107. android:text="男" />
  108. <RadioButton
  109. android:id="@+id/rb_woman"
  110. android:layout_width="wrap_content"
  111. android:layout_height="wrap_content"
  112. android:layout_marginLeft="50dp"
  113. android:text="女" />
  114. </RadioGroup>
  115. </LinearLayout>
  116. <LinearLayout
  117. android:layout_width="match_parent"
  118. android:layout_height="wrap_content"
  119. android:layout_marginTop="15dp"
  120. android:orientation="horizontal">
  121. <TextView
  122. android:id="@+id/tv_login"
  123. android:layout_width="wrap_content"
  124. android:layout_height="wrap_content"
  125. android:layout_weight="1"
  126. android:gravity="center|right"
  127. android:text="已有账号,立即登录!"
  128. android:textColor="#000"
  129. android:textSize="14sp" />
  130. </LinearLayout>
  131. <Button
  132. android:id="@+id/btn_register"
  133. android:layout_width="match_parent"
  134. android:layout_height="35dp"
  135. android:layout_marginTop="30dp"
  136. android:background="@drawable/btn_lr"
  137. android:text="立 即 注 册"
  138. android:textColor="#ffffff"
  139. android:textSize="14sp" />
  140. </LinearLayout>
  141. </LinearLayout>
  142. </androidx.constraintlayout.widget.ConstraintLayout>

        实现了用户注册的功能,包括输入个人信息并将其存储到数据库中。代码中还包括了针对用户输入信息完整性和密码一致性的检查,以及跳转到登录页面的功能。

  1. package com.example.dormitorymanagementsystem.UI_Public;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;
  6. import android.widget.EditText;
  7. import android.widget.RadioButton;
  8. import android.widget.RadioGroup;
  9. import android.widget.TextView;
  10. import android.widget.Toast;
  11. import androidx.appcompat.app.AppCompatActivity;
  12. import com.example.dormitorymanagementsystem.Bean.User;
  13. import com.example.dormitorymanagementsystem.Helper.UserHelper;
  14. import com.example.dormitorymanagementsystem.R;
  15. public class RegisterActivity extends AppCompatActivity {
  16. // 声明视图相关的变量
  17. private EditText etName;
  18. private EditText etNum;
  19. private EditText etPhone;
  20. private EditText etPass;
  21. private EditText etRpass;
  22. private RadioGroup rg;
  23. private RadioButton rbMan;
  24. private RadioButton rbWoman;
  25. private Button btnRegister;
  26. private TextView tvLogin;
  27. @Override
  28. protected void onCreate(Bundle savedInstanceState) {
  29. super.onCreate(savedInstanceState);
  30. setContentView(R.layout.activity_register);
  31. // 初始化视图
  32. initView();
  33. // 设置注册按钮的点击事件
  34. btnRegister.setOnClickListener(new View.OnClickListener() {
  35. @Override
  36. public void onClick(View v) {
  37. // 获取用户输入的注册信息
  38. String name = etName.getText().toString().trim();
  39. String num = etNum.getText().toString().trim();
  40. String phone = etPhone.getText().toString().trim();
  41. String password = etPass.getText().toString().trim();
  42. String repeatedPassword = etRpass.getText().toString().trim();
  43. String gender = getSelectedGender();
  44. // 检查信息是否填写完整
  45. if (name.isEmpty() || num.isEmpty() || phone.isEmpty() || password.isEmpty()
  46. || repeatedPassword.isEmpty() || gender.isEmpty()) {
  47. Toast.makeText(RegisterActivity.this, "请填写完整信息", Toast.LENGTH_SHORT).show();
  48. return;
  49. }
  50. // 检查密码是否一致
  51. if (!password.equals(repeatedPassword)) {
  52. Toast.makeText(RegisterActivity.this, "密码不一致", Toast.LENGTH_SHORT).show();
  53. return;
  54. }
  55. // 设置登录按钮的点击事件
  56. tvLogin.setOnClickListener(new View.OnClickListener() {
  57. @Override
  58. public void onClick(View v) {
  59. // 跳转到登录页面
  60. startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
  61. }
  62. });
  63. }
  64. // 获取选中的性别
  65. private String getSelectedGender() {
  66. switch (rg.getCheckedRadioButtonId()) {
  67. case R.id.rb_man:
  68. return "男";
  69. case R.id.rb_woman:
  70. return "女";
  71. default:
  72. return "";
  73. }
  74. }
  75. // 初始化视图
  76. private void initView() {
  77. etName = findViewById(R.id.et_name);
  78. etNum = findViewById(R.id.et_num);
  79. etPhone = findViewById(R.id.et_phone);
  80. etPass = findViewById(R.id.et_pass);
  81. etRpass = findViewById(R.id.et_rpass);
  82. rg = findViewById(R.id.rg);
  83. rbMan = findViewById(R.id.rb_man);
  84. rbWoman = findViewById(R.id.rb_woman);
  85. btnRegister = findViewById(R.id.btn_register);
  86. tvLogin = findViewById(R.id.tv_login);
  87. }
  88. }

1.3 登陆页面实现

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:background="#FFFEFE"
  8. tools:context=".UI_Public.LoginActivity">
  9. <View
  10. android:id="@+id/view"
  11. android:layout_width="wrap_content"
  12. android:layout_height="400dp"
  13. android:background="#1C367E"
  14. app:layout_constraintEnd_toEndOf="parent"
  15. app:layout_constraintStart_toStartOf="parent"
  16. app:layout_constraintTop_toTopOf="parent" />
  17. <ImageView
  18. android:id="@+id/imageView2"
  19. android:layout_width="0dp"
  20. android:layout_height="200dp"
  21. android:layout_marginTop="24dp"
  22. app:layout_constraintEnd_toEndOf="parent"
  23. app:layout_constraintStart_toStartOf="parent"
  24. app:layout_constraintTop_toTopOf="parent"
  25. app:srcCompat="@drawable/logo" />
  26. <LinearLayout
  27. android:id="@+id/linearLayout"
  28. android:layout_width="0dp"
  29. android:layout_height="wrap_content"
  30. android:layout_marginStart="32dp"
  31. android:layout_marginTop="8dp"
  32. android:layout_marginEnd="32dp"
  33. android:background="@drawable/view_lr"
  34. android:gravity="center|top"
  35. android:orientation="vertical"
  36. app:layout_constraintEnd_toEndOf="parent"
  37. app:layout_constraintStart_toStartOf="parent"
  38. app:layout_constraintTop_toBottomOf="@+id/imageView2">
  39. <LinearLayout
  40. android:layout_width="match_parent"
  41. android:layout_height="match_parent"
  42. android:layout_marginLeft="15dp"
  43. android:layout_marginTop="30dp"
  44. android:layout_marginRight="15dp"
  45. android:layout_marginBottom="30dp"
  46. android:orientation="vertical">
  47. <EditText
  48. android:id="@+id/et_number"
  49. android:layout_width="match_parent"
  50. android:layout_height="wrap_content"
  51. android:ems="10"
  52. android:hint="请输入学号!"
  53. android:inputType="textPersonName"
  54. android:textSize="14sp" />
  55. <EditText
  56. android:id="@+id/et_password"
  57. android:layout_width="match_parent"
  58. android:layout_height="wrap_content"
  59. android:layout_marginTop="30dp"
  60. android:ems="10"
  61. android:hint="请输入密码!"
  62. android:inputType="textPassword"
  63. android:textSize="14sp" />
  64. <LinearLayout
  65. android:layout_width="match_parent"
  66. android:layout_height="wrap_content"
  67. android:layout_marginTop="10dp"
  68. android:orientation="horizontal">
  69. <CheckBox
  70. android:id="@+id/cb_remember"
  71. android:layout_width="wrap_content"
  72. android:layout_height="wrap_content"
  73. android:layout_weight="1"
  74. android:text="记住密码"
  75. android:textSize="14sp" />
  76. <TextView
  77. android:id="@+id/tv_register"
  78. android:layout_width="wrap_content"
  79. android:layout_height="wrap_content"
  80. android:layout_weight="1"
  81. android:gravity="center|right"
  82. android:text="立即注册!"
  83. android:textColor="#000"
  84. android:textSize="14sp" />
  85. </LinearLayout>
  86. <LinearLayout
  87. android:layout_width="match_parent"
  88. android:layout_height="wrap_content"
  89. android:layout_marginTop="20dp"
  90. android:orientation="horizontal">
  91. <RadioGroup
  92. android:id="@+id/rg"
  93. android:layout_width="match_parent"
  94. android:layout_height="match_parent"
  95. android:gravity="center"
  96. android:orientation="horizontal">
  97. <RadioButton
  98. android:id="@+id/rb_student"
  99. android:layout_width="wrap_content"
  100. android:layout_height="wrap_content"
  101. android:checked="false"
  102. android:text="学生" />
  103. <RadioButton
  104. android:id="@+id/rb_admin"
  105. android:layout_width="wrap_content"
  106. android:layout_height="wrap_content"
  107. android:layout_marginLeft="50dp"
  108. android:text="管理员" />
  109. </RadioGroup>
  110. </LinearLayout>
  111. <Button
  112. android:id="@+id/btn_login"
  113. android:layout_width="match_parent"
  114. android:layout_height="35dp"
  115. android:layout_marginTop="30dp"
  116. android:background="@drawable/btn_lr"
  117. android:text="立 即 登 录"
  118. android:textColor="#ffffff"
  119. android:textSize="14sp" />
  120. </LinearLayout>
  121. </LinearLayout>
  122. </androidx.constraintlayout.widget.ConstraintLayout>

        这段代码实现了一个简单的登录页面,可以输入用户名和密码进行登录,可以选择是否保存密码,还可以跳转到注册页面进行账号注册。

  1. package com.example.dormitorymanagementsystem.UI_Public;
  2. import android.content.Intent;
  3. import android.content.SharedPreferences;
  4. import android.os.Bundle;
  5. import android.text.TextUtils;
  6. import android.widget.CheckBox;
  7. import android.widget.EditText;
  8. import android.widget.RadioButton;
  9. import android.widget.RadioGroup;
  10. import android.widget.Toast;
  11. import androidx.appcompat.app.AppCompatActivity;
  12. import com.example.dormitorymanagementsystem.Helper.UserHelper;
  13. import com.example.dormitorymanagementsystem.R;
  14. import com.example.dormitorymanagementsystem.UI_Admin.AdminActivity;
  15. import com.example.dormitorymanagementsystem.UI_Student.StudentActivity;
  16. public class LoginActivity extends AppCompatActivity {
  17. // 控件声明
  18. private EditText etNumber, etPassword;
  19. private CheckBox cbRemember;
  20. private RadioButton rbStudent, rbAdmin;
  21. private RadioGroup rg;
  22. private UserHelper userHelper;
  23. @Override
  24. protected void onCreate(Bundle savedInstanceState) {
  25. super.onCreate(savedInstanceState);
  26. setContentView(R.layout.activity_login);
  27. initView(); // 获取控件
  28. initSavedLoginInfo(); // 初始化已保存的登录信息
  29. setListeners(); // 设置点击事件处理
  30. }
  31. // 获取控件
  32. private void initView() {
  33. etNumber = findViewById(R.id.et_number);
  34. etPassword = findViewById(R.id.et_password);
  35. cbRemember = findViewById(R.id.cb_remember);
  36. rbStudent = findViewById(R.id.rb_student);
  37. rbAdmin = findViewById(R.id.rb_admin);
  38. rg = findViewById(R.id.rg);
  39. userHelper = new UserHelper(this);
  40. }
  41. // 设置点击事件处理
  42. private void setListeners() {
  43. // 跳转注册页面
  44. findViewById(R.id.tv_register).setOnClickListener(v -> {
  45. startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
  46. finish();
  47. });
  48. findViewById(R.id.btn_login).setOnClickListener(v -> {
  49. int selectedId = rg.getCheckedRadioButtonId();
  50. if (selectedId == R.id.rb_student) {
  51. onStudentLoginClicked(); // 调用学生登录逻辑
  52. } else if (selectedId == R.id.rb_admin) {
  53. onAdminLoginClicked(); // 调用管理员登录逻辑
  54. }
  55. });
  56. }
  57. // 处理学生登录逻辑
  58. private void onStudentLoginClicked() {
  59. String number = etNumber.getText().toString().trim();
  60. String password = etPassword.getText().toString().trim();
  61. boolean remember = cbRemember.isChecked();
  62. int selectedId = R.id.rb_student;
  63. if (TextUtils.isEmpty(number) || TextUtils.isEmpty(password)) {
  64. Toast.makeText(LoginActivity.this, "学号或密码不能为空!", Toast.LENGTH_SHORT).show();
  65. } else {
  66. if (result) {
  67. saveAccountInfo(number);//单独保存用户账号,进行信息查询使用
  68. saveLoginInfo(remember, number, password, selectedId); // 保存登录信息,并传入选择的身份
  69. startActivity(new Intent(LoginActivity.this, StudentActivity.class)); // 跳转到 StudentActivity
  70. finish();
  71. } else {
  72. Toast.makeText(LoginActivity.this, "登录失败,学号或密码错误!", Toast.LENGTH_SHORT).show();
  73. }
  74. }
  75. }
  76. // 处理管理员登录逻辑
  77. private void onAdminLoginClicked() {
  78. if (TextUtils.isEmpty(adminId) || TextUtils.isEmpty(adminPassword)) {
  79. Toast.makeText(LoginActivity.this, "管理员账号或密码不能为空", Toast.LENGTH_SHORT).show();
  80. } else {
  81. if (adminId.equals("admin") && adminPassword.equals("admin")) {
  82. saveAccountInfo(adminId);//单独保存用户账号,进行信息查询使用
  83. saveLoginInfo(remember, adminId, adminPassword, selectedId); // 保存登录信息,并传入选择的身份
  84. startActivity(new Intent(LoginActivity.this, AdminActivity.class)); // 跳转AdminActivity页面
  85. finish();
  86. } else {
  87. Toast.makeText(LoginActivity.this, "管理员登录失败", Toast.LENGTH_SHORT).show();
  88. }
  89. }
  90. }
  91. }

1.4 学生首页实现

        

        在onCreateView方法中,通过获取相应的控件,初始化界面。其中,轮播图部分使用第三方库Banner实现,展示了一组图片。

        通知信息部分从SharedPreferences中获取存储的通知数据,并显示在界面上。

        宿舍学生列表部分通过调用UserHelper类的方法,根据当前学号获取到学生所在的宿舍号,再根据宿舍号获取该宿舍的学生信息列表,并显示在RecyclerView中。

        notice方法用于显示通知信息,在SharedPreferences中获取并显示相关数据。如果没有找到通知信息,则显示"暂无数据"。

        getNumber方法从SharedPreferences中获取当前学号。

        banner方法用于设置轮播图,使用了第三方库Banner来实现。通过设置圆角效果,展示一组图片。

  1. package com.example.dormitorymanagementsystem.UI_Student;
  2. import android.content.Context;
  3. import android.content.SharedPreferences;
  4. import android.graphics.Outline;
  5. import android.os.Bundle;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.view.ViewOutlineProvider;
  10. import android.widget.ImageView;
  11. import android.widget.LinearLayout;
  12. import android.widget.TextView;
  13. import androidx.fragment.app.Fragment;
  14. import androidx.recyclerview.widget.LinearLayoutManager;
  15. import androidx.recyclerview.widget.RecyclerView;
  16. import com.example.dormitorymanagementsystem.Adapter.DormitoryAdapter;
  17. import com.example.dormitorymanagementsystem.Bean.User;
  18. import com.example.dormitorymanagementsystem.Helper.UserHelper;
  19. import com.example.dormitorymanagementsystem.R;
  20. import com.youth.banner.Banner;
  21. import com.youth.banner.loader.ImageLoader;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import static android.content.Context.MODE_PRIVATE;
  25. public class StudentHomeFragment extends Fragment {
  26. private Banner banner;
  27. private TextView textView;
  28. private TextView textView2;
  29. private TextView tvTitle;
  30. private TextView tvTime;
  31. private TextView tvContent;
  32. private TextView tvDormitory;
  33. private RecyclerView rv;
  34. private LinearLayout llTongzhi;
  35. private TextView tvTongzhi;
  36. private DormitoryAdapter adapter;
  37. private List<User> userList;
  38. private String number;
  39. @Override
  40. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  41. Bundle savedInstanceState) {
  42. View v = inflater.inflate(R.layout.fragment_student_home, container, false);
  43. initView(v);
  44. banner(v);
  45. getNumber();
  46. // 获取并显示宿舍学生信息
  47. tvDormitory.setText("宿舍--("+dormitory+")");
  48. return v;
  49. }
  50. // 显示通知
  51. private void notice() {
  52. // 从 SharedPreferences 中获取通知信息
  53. SharedPreferences sharedPreferences = getActivity().getSharedPreferences("notice", Context.MODE_PRIVATE);
  54. }
  55. // 获取当前学号
  56. private void getNumber() {
  57. SharedPreferences sharedPreferences = getActivity().getSharedPreferences("AccountInfo", MODE_PRIVATE);
  58. number = sharedPreferences.getString("number", "defaultValue");
  59. }
  60. // 顶部轮播图
  61. private void banner(View v) {
  62. List list = new ArrayList();
  63. list.add(R.drawable.lb01);
  64. list.add(R.drawable.lb03);
  65. list.add(R.drawable.lb02);
  66. }
  67. // 获取控件
  68. private void initView(View v) {
  69. banner = v.findViewById(R.id.banner);
  70. textView = v.findViewById(R.id.textView);
  71. textView2 = v.findViewById(R.id.textView2);
  72. tvTitle = v.findViewById(R.id.tv_title);
  73. tvTime = v.findViewById(R.id.tv_time);
  74. tvContent = v.findViewById(R.id.tv_content);
  75. tvDormitory = v.findViewById(R.id.tv_dormitory);
  76. rv = v.findViewById(R.id.rv);
  77. llTongzhi = v.findViewById(R.id.ll_tongzhi);
  78. tvTongzhi = v.findViewById(R.id.tv_tongzhi);
  79. userHelper = new UserHelper(getContext());
  80. }
  81. }

对应的布局文件代码如下所示:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".UI_Student.StudentHomeFragment">
  8. <LinearLayout
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:orientation="vertical"
  12. app:layout_constraintBottom_toBottomOf="parent"
  13. app:layout_constraintEnd_toEndOf="parent"
  14. app:layout_constraintStart_toStartOf="parent"
  15. app:layout_constraintTop_toTopOf="parent">
  16. <com.youth.banner.Banner
  17. android:id="@+id/banner"
  18. android:layout_width="match_parent"
  19. android:layout_height="150dp"
  20. android:layout_marginStart="16dp"
  21. android:layout_marginTop="16dp"
  22. android:layout_marginEnd="16dp">
  23. </com.youth.banner.Banner>
  24. <LinearLayout
  25. android:layout_width="match_parent"
  26. android:layout_height="wrap_content"
  27. android:layout_marginLeft="16dp"
  28. android:layout_marginTop="16dp"
  29. android:layout_marginRight="16dp"
  30. android:orientation="horizontal">
  31. <TextView
  32. android:id="@+id/textView"
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"
  35. android:text="最新"
  36. android:textColor="#03A9F4"
  37. android:textSize="15sp"
  38. android:textStyle="bold|italic" />
  39. <TextView
  40. android:id="@+id/textView2"
  41. android:layout_width="35dp"
  42. android:layout_height="wrap_content"
  43. android:text="通知"
  44. android:textColor="#FF0000"
  45. android:textSize="15sp"
  46. android:textStyle="bold|italic" />
  47. </LinearLayout>
  48. <LinearLayout
  49. android:id="@+id/ll_tongzhi"
  50. android:layout_width="match_parent"
  51. android:layout_height="wrap_content"
  52. android:orientation="vertical"
  53. tools:layout_editor_absoluteY="731dp">
  54. <TextView
  55. android:id="@+id/tv_title"
  56. android:layout_width="match_parent"
  57. android:layout_height="wrap_content"
  58. android:gravity="center"
  59. android:text="宿舍人员查询"
  60. android:textColor=" #000"
  61. android:textSize="18sp"
  62. android:textStyle="bold" />
  63. <TextView
  64. android:id="@+id/tv_time"
  65. android:layout_width="match_parent"
  66. android:layout_height="wrap_content"
  67. android:layout_marginTop="5dp"
  68. android:gravity="center"
  69. android:text="发布时间:2024.02.01"
  70. android:textSize="10sp" />
  71. <TextView
  72. android:id="@+id/tv_content"
  73. android:layout_width="match_parent"
  74. android:layout_height="wrap_content"
  75. android:layout_marginLeft="16dp"
  76. android:layout_marginTop="5dp"
  77. android:layout_marginRight="16dp"
  78. android:layout_marginBottom="10dp"
  79. android:text="\t\t\t\t请新注册的同学在我的页面个人信息一栏点击填写宿舍、班级,填写后可以查询同宿舍人员!"
  80. android:textColor="#000"
  81. android:textSize="12sp" />
  82. </LinearLayout>
  83. <TextView
  84. android:id="@+id/tv_dormitory"
  85. android:layout_width="wrap_content"
  86. android:layout_height="wrap_content"
  87. android:layout_marginLeft="16dp"
  88. android:layout_marginTop="10dp"
  89. android:layout_marginRight="16dp"
  90. android:text="宿舍(3-1-9)"
  91. android:textColor="#03A9F4"
  92. android:textSize="15sp"
  93. android:textStyle="bold" />
  94. <ScrollView
  95. android:id="@+id/scrollView2"
  96. android:layout_width="match_parent"
  97. android:layout_height="wrap_content"
  98. android:layout_marginTop="8dp">
  99. <LinearLayout
  100. android:layout_width="match_parent"
  101. android:layout_height="wrap_content"
  102. android:orientation="vertical">
  103. <TextView
  104. android:id="@+id/tv_tongzhi"
  105. android:layout_width="match_parent"
  106. android:layout_height="wrap_content"
  107. android:layout_marginLeft="16dp"
  108. android:layout_marginTop="10dp"
  109. android:layout_marginRight="16dp"
  110. android:layout_marginBottom="10dp"
  111. android:gravity="center"
  112. android:text="暂无数据,登记宿舍后查看!"
  113. android:visibility="gone" />
  114. <androidx.recyclerview.widget.RecyclerView
  115. android:id="@+id/rv"
  116. android:layout_width="match_parent"
  117. android:layout_height="match_parent"
  118. android:layout_marginLeft="16dp"
  119. android:layout_marginTop="8dp"
  120. android:layout_marginRight="16dp"
  121. android:layout_marginBottom="10dp" />
  122. </LinearLayout>
  123. </ScrollView>
  124. </LinearLayout>
  125. </androidx.constraintlayout.widget.ConstraintLayout>

 1.5 学生我的页面实现               

        这段代码是一个名为`StudentMineFragment`的类,它实现了一个`Fragment`界面,用于展示学生个人信息和一些交互操作。下面是它的功能和逻辑总结:

1. 当用户点击“个人信息”时,会跳转到个人信息界面。

2. 当用户点击“修改密码”时,会弹出一个自定义对话框,允许用户输入新密码,然后调用方法来更新密码,并根据返回结果来判断是否修改成功。如果成功,则清空登录时保存的数据,跳转到`LoginActivity`界面,并显示修改成功提示;如果失败,则显示修改失败提示。

3. 当用户点击“退出登录”时,会跳转到`LoginActivity`界面,并关闭当前界面。

        此外,代码中使用了`SharedPreferences`来保存和获取学生的学号等信息,并使用`Toast`来显示相关提示信息。

1.6 学生个人信息页面实现

        主要实现了查询学生信息、修改学生信息和返回主页等功能。在onCreate方法中,通过initView()方法初始化控件,然后通过getNumber()方法获取当前学号,接着调用search()方法查询学生信息并显示在对应的视图中,最后分别设置了返回主页和修改信息的点击事件。

        其中,点击"修改信息"按钮时,会获取用户输入的信息并进行判空和判断待填写信息的逻辑,然后调用方法来更新用户信息,并根据更新结果显示相应的提示信息。

1.7 管理员首页页面实现 

1. 初始化视图并设置监听器。

2. 在`show()`方法中,默认显示所有学生的信息。首先通过`UserHelper`对象获取所有学生的列表,并将其传递给`AdminStudentAdapter`适配器,然后将适配器设置给`RecyclerView`控件进行显示。

3. 在`search()`方法中,通过点击搜索按钮查询对应的学生信息。首先获取管理员输入的学号,然后通过`UserHelper`对象根据学号获取对应的学生对象,将其添加到一个新的学生列表中,并将新的列表传递给`AdminStudentAdapter`适配器进行显示。

4. 在`search()`方法中,如果管理员未输入学号,则调用`show()`方法显示所有学生信息。

5. 在`search()`方法中,如果查询结果为空,则显示一个提示信息,并清空适配器中的数据。

        此外,在`initView()`方法中,获取了各个控件的引用,并创建了一个`UserHelper`对象来辅助数据库操作。

1.8 管理员我的页面实现

        首先,通过`onCreateView`方法初始化了界面布局,并在`initView`中获取了相关的控件,并设置了点击事件监听。

在`onClick`方法中,针对不同的点击事件进行了处理:

1. 点击个人信息(`llInformation`):弹出自定义对话框用于显示和修改个人信息。

2. 点击发布公告(`llNotice`):跳转到发布公告页面(`AdminNoticeActivity`)。

3. 点击添加学生(`llAddStudent`):跳转到添加学生页面(`AdminAddStudentActivity`)。

4. 点击退出登录(`llExit`):跳转到登录页面(`LoginActivity`),并关闭当前的活动。

        整体来说,该页面实现了管理员个人页面的基本功能,包括了界面展示和各种操作的处理。

1.9 发布公告页面实现

1. 在`onCreate`方法中,初始化视图并设置点击事件。

2. `clear`方法用于清空当前内容,当点击`btnClear`按钮时,会清空`etTitle`、`etTime`和`etContent`的文本内容。

3. `back`方法用于返回,当点击`imgBack`图片时,会调用`finish`方法关闭当前活动。

4. `showNotice`方法用于显示通知,首先通过`getSharedPreferences`方法获取名为"notice"的`SharedPreferences`对象。

  - 如果找到了该对象,就从中获取保存的通知标题、时间和内容,并在界面上显示出来。

  - 如果没有找到该对象,则显示默认信息。

5. `publishNotice`方法用于发布通知,当点击`btnPublish`按钮时,会获取输入框中的通知标题、时间和内容,并将它们存储在名为"notice"的`SharedPreferences`对象中。

  最后,会显示一个提示用户通知发布成功的`Toast`消息。

1.10 添加学生页面实现     

- 绑定返回按钮的点击事件,点击返回按钮会关闭当前活动。

- 绑定添加按钮的点击事件,点击添加按钮会将用户输入的学生信息插入数据库。

- 获取用户输入的学生信息,并进行信息完整性检查。

- 查询数据库,检查学生账号是否已存在。如果账号已存在,会显示提示信息。

- 如果账号未添加过,将学生信息插入数据库。

- 添加成功后会清空输入框,并清除性别选择。

      到此为止,我们的项目就已经完成了! 

Get 项目模板源码

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/791522
推荐阅读
相关标签