赞
踩
目录
Android studio毕业设计~宿舍管理系统
- <?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"
- android:background="#1C367E "
- tools:context=".UI_Public.StartActivity">
-
- <ImageView
- android:id="@+id/imageView"
- android:layout_width="0dp"
- android:layout_height="0dp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:srcCompat="@drawable/logo" />
- </androidx.constraintlayout.widget.ConstraintLayout>
- <?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"
- android:background="#FFFEFE"
- tools:context=".UI_Public.RegisterActivity">
-
- <View
- android:id="@+id/view"
- android:layout_width="wrap_content"
- android:layout_height="400dp"
- android:background="#1C367E"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
-
- <ImageView
- android:id="@+id/imageView2"
- android:layout_width="0dp"
- android:layout_height="200dp"
- android:layout_marginTop="24dp"
- app:layout_constraintEnd_toEndOf="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="wrap_content"
- android:layout_marginStart="32dp"
- android:layout_marginTop="8dp"
- android:layout_marginEnd="32dp"
- android:background="@drawable/view_lr"
- android:gravity="center|top"
- android:orientation="vertical"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/imageView2">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginLeft="15dp"
- android:layout_marginTop="20dp"
- android:layout_marginRight="15dp"
- android:layout_marginBottom="20dp"
- android:orientation="vertical">
-
- <EditText
- android:id="@+id/et_name"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:ems="10"
- android:hint="请输入姓名!"
- android:inputType="textPersonName"
- android:textSize="14sp" />
-
- <EditText
- android:id="@+id/et_num"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:ems="10"
- android:hint="请输入学号!"
- android:inputType="textPersonName"
- android:textSize="14sp" />
-
- <EditText
- android:id="@+id/et_phone"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:ems="10"
- android:hint="请输入电话号码!"
- android:inputType="phone"
- android:textSize="14sp" />
-
- <EditText
- android:id="@+id/et_pass"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:ems="10"
- android:hint="请输入密码!"
- android:inputType="textPassword"
- android:textSize="14sp" />
-
- <EditText
- android:id="@+id/et_rpass"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:ems="10"
- android:hint="请再次输入密码!"
- android:inputType="textPassword"
- android:textSize="14sp" />
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:orientation="horizontal">
-
- <RadioGroup
- android:id="@+id/rg"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:orientation="horizontal">
-
- <RadioButton
- android:id="@+id/rb_man"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:checked="true"
- android:text="男" />
-
- <RadioButton
- android:id="@+id/rb_woman"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="50dp"
- android:text="女" />
- </RadioGroup>
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:orientation="horizontal">
-
-
- <TextView
- android:id="@+id/tv_login"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:gravity="center|right"
- android:text="已有账号,立即登录!"
- android:textColor="#000"
- android:textSize="14sp" />
- </LinearLayout>
-
-
- <Button
- android:id="@+id/btn_register"
- android:layout_width="match_parent"
- android:layout_height="35dp"
- android:layout_marginTop="30dp"
- android:background="@drawable/btn_lr"
- android:text="立 即 注 册"
- android:textColor="#ffffff"
- android:textSize="14sp" />
-
- </LinearLayout>
-
- </LinearLayout>
- </androidx.constraintlayout.widget.ConstraintLayout>
实现了用户注册的功能,包括输入个人信息并将其存储到数据库中。代码中还包括了针对用户输入信息完整性和密码一致性的检查,以及跳转到登录页面的功能。
- package com.example.dormitorymanagementsystem.UI_Public;
-
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- import android.widget.Toast;
-
- import androidx.appcompat.app.AppCompatActivity;
-
- import com.example.dormitorymanagementsystem.Bean.User;
- import com.example.dormitorymanagementsystem.Helper.UserHelper;
- import com.example.dormitorymanagementsystem.R;
-
- public class RegisterActivity extends AppCompatActivity {
-
- // 声明视图相关的变量
- private EditText etName;
- private EditText etNum;
- private EditText etPhone;
- private EditText etPass;
- private EditText etRpass;
- private RadioGroup rg;
- private RadioButton rbMan;
- private RadioButton rbWoman;
- private Button btnRegister;
- private TextView tvLogin;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
-
- // 初始化视图
- initView();
-
- // 设置注册按钮的点击事件
- btnRegister.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // 获取用户输入的注册信息
- String name = etName.getText().toString().trim();
- String num = etNum.getText().toString().trim();
- String phone = etPhone.getText().toString().trim();
- String password = etPass.getText().toString().trim();
- String repeatedPassword = etRpass.getText().toString().trim();
- String gender = getSelectedGender();
-
- // 检查信息是否填写完整
- if (name.isEmpty() || num.isEmpty() || phone.isEmpty() || password.isEmpty()
- || repeatedPassword.isEmpty() || gender.isEmpty()) {
- Toast.makeText(RegisterActivity.this, "请填写完整信息", Toast.LENGTH_SHORT).show();
- return;
- }
-
- // 检查密码是否一致
- if (!password.equals(repeatedPassword)) {
- Toast.makeText(RegisterActivity.this, "密码不一致", Toast.LENGTH_SHORT).show();
- return;
- }
-
-
-
- // 设置登录按钮的点击事件
- tvLogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // 跳转到登录页面
- startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
- }
- });
- }
-
- // 获取选中的性别
- private String getSelectedGender() {
- switch (rg.getCheckedRadioButtonId()) {
- case R.id.rb_man:
- return "男";
- case R.id.rb_woman:
- return "女";
- default:
- return "";
- }
- }
-
- // 初始化视图
- private void initView() {
- etName = findViewById(R.id.et_name);
- etNum = findViewById(R.id.et_num);
- etPhone = findViewById(R.id.et_phone);
- etPass = findViewById(R.id.et_pass);
- etRpass = findViewById(R.id.et_rpass);
- rg = findViewById(R.id.rg);
- rbMan = findViewById(R.id.rb_man);
- rbWoman = findViewById(R.id.rb_woman);
- btnRegister = findViewById(R.id.btn_register);
- tvLogin = findViewById(R.id.tv_login);
- }
- }
- <?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"
- android:background="#FFFEFE"
- tools:context=".UI_Public.LoginActivity">
-
- <View
- android:id="@+id/view"
- android:layout_width="wrap_content"
- android:layout_height="400dp"
- android:background="#1C367E"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
-
- <ImageView
- android:id="@+id/imageView2"
- android:layout_width="0dp"
- android:layout_height="200dp"
- android:layout_marginTop="24dp"
- app:layout_constraintEnd_toEndOf="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="wrap_content"
- android:layout_marginStart="32dp"
- android:layout_marginTop="8dp"
- android:layout_marginEnd="32dp"
- android:background="@drawable/view_lr"
- android:gravity="center|top"
- android:orientation="vertical"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/imageView2">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginLeft="15dp"
- android:layout_marginTop="30dp"
- android:layout_marginRight="15dp"
- android:layout_marginBottom="30dp"
- android:orientation="vertical">
-
- <EditText
- android:id="@+id/et_number"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:ems="10"
- android:hint="请输入学号!"
- android:inputType="textPersonName"
- android:textSize="14sp" />
-
- <EditText
- android:id="@+id/et_password"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="30dp"
- android:ems="10"
- android:hint="请输入密码!"
- android:inputType="textPassword"
- android:textSize="14sp" />
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dp"
- android:orientation="horizontal">
-
- <CheckBox
- android:id="@+id/cb_remember"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="记住密码"
- android:textSize="14sp" />
-
- <TextView
- android:id="@+id/tv_register"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:gravity="center|right"
- android:text="立即注册!"
- android:textColor="#000"
- android:textSize="14sp" />
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="20dp"
- android:orientation="horizontal">
-
- <RadioGroup
- android:id="@+id/rg"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:orientation="horizontal">
-
- <RadioButton
- android:id="@+id/rb_student"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:checked="false"
- android:text="学生" />
-
- <RadioButton
- android:id="@+id/rb_admin"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="50dp"
- android:text="管理员" />
- </RadioGroup>
- </LinearLayout>
-
- <Button
- android:id="@+id/btn_login"
- android:layout_width="match_parent"
- android:layout_height="35dp"
- android:layout_marginTop="30dp"
- android:background="@drawable/btn_lr"
- android:text="立 即 登 录"
- android:textColor="#ffffff"
- android:textSize="14sp" />
-
- </LinearLayout>
-
- </LinearLayout>
- </androidx.constraintlayout.widget.ConstraintLayout>
这段代码实现了一个简单的登录页面,可以输入用户名和密码进行登录,可以选择是否保存密码,还可以跳转到注册页面进行账号注册。
- package com.example.dormitorymanagementsystem.UI_Public;
-
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.text.TextUtils;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.Toast;
-
- import androidx.appcompat.app.AppCompatActivity;
-
- import com.example.dormitorymanagementsystem.Helper.UserHelper;
- import com.example.dormitorymanagementsystem.R;
- import com.example.dormitorymanagementsystem.UI_Admin.AdminActivity;
- import com.example.dormitorymanagementsystem.UI_Student.StudentActivity;
-
- public class LoginActivity extends AppCompatActivity {
-
- // 控件声明
- private EditText etNumber, etPassword;
- private CheckBox cbRemember;
- private RadioButton rbStudent, rbAdmin;
- private RadioGroup rg;
- private UserHelper userHelper;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
-
- initView(); // 获取控件
-
- initSavedLoginInfo(); // 初始化已保存的登录信息
-
- setListeners(); // 设置点击事件处理
- }
-
- // 获取控件
- private void initView() {
- etNumber = findViewById(R.id.et_number);
- etPassword = findViewById(R.id.et_password);
- cbRemember = findViewById(R.id.cb_remember);
- rbStudent = findViewById(R.id.rb_student);
- rbAdmin = findViewById(R.id.rb_admin);
- rg = findViewById(R.id.rg);
- userHelper = new UserHelper(this);
- }
- // 设置点击事件处理
- private void setListeners() {
- // 跳转注册页面
- findViewById(R.id.tv_register).setOnClickListener(v -> {
- startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
- finish();
- });
-
- findViewById(R.id.btn_login).setOnClickListener(v -> {
- int selectedId = rg.getCheckedRadioButtonId();
- if (selectedId == R.id.rb_student) {
- onStudentLoginClicked(); // 调用学生登录逻辑
- } else if (selectedId == R.id.rb_admin) {
- onAdminLoginClicked(); // 调用管理员登录逻辑
- }
- });
- }
-
- // 处理学生登录逻辑
- private void onStudentLoginClicked() {
- String number = etNumber.getText().toString().trim();
- String password = etPassword.getText().toString().trim();
- boolean remember = cbRemember.isChecked();
- int selectedId = R.id.rb_student;
-
- if (TextUtils.isEmpty(number) || TextUtils.isEmpty(password)) {
- Toast.makeText(LoginActivity.this, "学号或密码不能为空!", Toast.LENGTH_SHORT).show();
- } else {
- if (result) {
- saveAccountInfo(number);//单独保存用户账号,进行信息查询使用
- saveLoginInfo(remember, number, password, selectedId); // 保存登录信息,并传入选择的身份
- startActivity(new Intent(LoginActivity.this, StudentActivity.class)); // 跳转到 StudentActivity
- finish();
- } else {
- Toast.makeText(LoginActivity.this, "登录失败,学号或密码错误!", Toast.LENGTH_SHORT).show();
- }
- }
- }
-
- // 处理管理员登录逻辑
- private void onAdminLoginClicked() {
- if (TextUtils.isEmpty(adminId) || TextUtils.isEmpty(adminPassword)) {
- Toast.makeText(LoginActivity.this, "管理员账号或密码不能为空", Toast.LENGTH_SHORT).show();
- } else {
- if (adminId.equals("admin") && adminPassword.equals("admin")) {
- saveAccountInfo(adminId);//单独保存用户账号,进行信息查询使用
- saveLoginInfo(remember, adminId, adminPassword, selectedId); // 保存登录信息,并传入选择的身份
- startActivity(new Intent(LoginActivity.this, AdminActivity.class)); // 跳转AdminActivity页面
- finish();
- } else {
- Toast.makeText(LoginActivity.this, "管理员登录失败", Toast.LENGTH_SHORT).show();
- }
- }
- }
-
-
- }
在onCreateView方法中,通过获取相应的控件,初始化界面。其中,轮播图部分使用第三方库Banner实现,展示了一组图片。
通知信息部分从SharedPreferences中获取存储的通知数据,并显示在界面上。
宿舍学生列表部分通过调用UserHelper类的方法,根据当前学号获取到学生所在的宿舍号,再根据宿舍号获取该宿舍的学生信息列表,并显示在RecyclerView中。
notice方法用于显示通知信息,在SharedPreferences中获取并显示相关数据。如果没有找到通知信息,则显示"暂无数据"。
getNumber方法从SharedPreferences中获取当前学号。
banner方法用于设置轮播图,使用了第三方库Banner来实现。通过设置圆角效果,展示一组图片。
- package com.example.dormitorymanagementsystem.UI_Student;
-
- import android.content.Context;
- import android.content.SharedPreferences;
- import android.graphics.Outline;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.ViewOutlineProvider;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.TextView;
-
- import androidx.fragment.app.Fragment;
- import androidx.recyclerview.widget.LinearLayoutManager;
- import androidx.recyclerview.widget.RecyclerView;
-
- import com.example.dormitorymanagementsystem.Adapter.DormitoryAdapter;
- import com.example.dormitorymanagementsystem.Bean.User;
- import com.example.dormitorymanagementsystem.Helper.UserHelper;
- import com.example.dormitorymanagementsystem.R;
- import com.youth.banner.Banner;
- import com.youth.banner.loader.ImageLoader;
-
- import java.util.ArrayList;
- import java.util.List;
-
- import static android.content.Context.MODE_PRIVATE;
-
- public class StudentHomeFragment extends Fragment {
-
- private Banner banner;
- private TextView textView;
- private TextView textView2;
- private TextView tvTitle;
- private TextView tvTime;
- private TextView tvContent;
- private TextView tvDormitory;
- private RecyclerView rv;
- private LinearLayout llTongzhi;
- private TextView tvTongzhi;
- private DormitoryAdapter adapter;
- private List<User> userList;
- private String number;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.fragment_student_home, container, false);
- initView(v);
- banner(v);
- getNumber();
- // 获取并显示宿舍学生信息
-
- tvDormitory.setText("宿舍--("+dormitory+")");
- return v;
- }
-
- // 显示通知
- private void notice() {
- // 从 SharedPreferences 中获取通知信息
- SharedPreferences sharedPreferences = getActivity().getSharedPreferences("notice", Context.MODE_PRIVATE);
- }
- // 获取当前学号
- private void getNumber() {
- SharedPreferences sharedPreferences = getActivity().getSharedPreferences("AccountInfo", MODE_PRIVATE);
- number = sharedPreferences.getString("number", "defaultValue");
- }
-
- // 顶部轮播图
- private void banner(View v) {
- List list = new ArrayList();
- list.add(R.drawable.lb01);
- list.add(R.drawable.lb03);
- list.add(R.drawable.lb02);
- }
-
- // 获取控件
- private void initView(View v) {
- banner = v.findViewById(R.id.banner);
- textView = v.findViewById(R.id.textView);
- textView2 = v.findViewById(R.id.textView2);
- tvTitle = v.findViewById(R.id.tv_title);
- tvTime = v.findViewById(R.id.tv_time);
- tvContent = v.findViewById(R.id.tv_content);
- tvDormitory = v.findViewById(R.id.tv_dormitory);
- rv = v.findViewById(R.id.rv);
- llTongzhi = v.findViewById(R.id.ll_tongzhi);
- tvTongzhi = v.findViewById(R.id.tv_tongzhi);
- userHelper = new UserHelper(getContext());
- }
- }
对应的布局文件代码如下所示:
- <?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=".UI_Student.StudentHomeFragment">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent">
-
- <com.youth.banner.Banner
- android:id="@+id/banner"
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:layout_marginStart="16dp"
- android:layout_marginTop="16dp"
- android:layout_marginEnd="16dp">
-
- </com.youth.banner.Banner>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginTop="16dp"
- android:layout_marginRight="16dp"
- android:orientation="horizontal">
-
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="最新"
- android:textColor="#03A9F4"
- android:textSize="15sp"
- android:textStyle="bold|italic" />
-
- <TextView
- android:id="@+id/textView2"
- android:layout_width="35dp"
- android:layout_height="wrap_content"
- android:text="通知"
- android:textColor="#FF0000"
- android:textSize="15sp"
- android:textStyle="bold|italic" />
- </LinearLayout>
-
- <LinearLayout
- android:id="@+id/ll_tongzhi"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- tools:layout_editor_absoluteY="731dp">
-
- <TextView
- android:id="@+id/tv_title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:text="宿舍人员查询"
- android:textColor=" #000"
- android:textSize="18sp"
- android:textStyle="bold" />
-
- <TextView
- android:id="@+id/tv_time"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="5dp"
- android:gravity="center"
- android:text="发布时间:2024.02.01"
- android:textSize="10sp" />
-
- <TextView
- android:id="@+id/tv_content"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginTop="5dp"
- android:layout_marginRight="16dp"
- android:layout_marginBottom="10dp"
- android:text="\t\t\t\t请新注册的同学在我的页面个人信息一栏点击填写宿舍、班级,填写后可以查询同宿舍人员!"
- android:textColor="#000"
- android:textSize="12sp" />
-
- </LinearLayout>
-
- <TextView
- android:id="@+id/tv_dormitory"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginTop="10dp"
- android:layout_marginRight="16dp"
- android:text="宿舍(3-1-9)"
- android:textColor="#03A9F4"
- android:textSize="15sp"
- android:textStyle="bold" />
-
- <ScrollView
- android:id="@+id/scrollView2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dp">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
-
- <TextView
- android:id="@+id/tv_tongzhi"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginTop="10dp"
- android:layout_marginRight="16dp"
- android:layout_marginBottom="10dp"
- android:gravity="center"
- android:text="暂无数据,登记宿舍后查看!"
- android:visibility="gone" />
-
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/rv"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginLeft="16dp"
- android:layout_marginTop="8dp"
- android:layout_marginRight="16dp"
- android:layout_marginBottom="10dp" />
-
- </LinearLayout>
- </ScrollView>
-
- </LinearLayout>
-
-
-
- </androidx.constraintlayout.widget.ConstraintLayout>
这段代码是一个名为`StudentMineFragment`的类,它实现了一个`Fragment`界面,用于展示学生个人信息和一些交互操作。下面是它的功能和逻辑总结:
1. 当用户点击“个人信息”时,会跳转到个人信息界面。
2. 当用户点击“修改密码”时,会弹出一个自定义对话框,允许用户输入新密码,然后调用方法来更新密码,并根据返回结果来判断是否修改成功。如果成功,则清空登录时保存的数据,跳转到`LoginActivity`界面,并显示修改成功提示;如果失败,则显示修改失败提示。
3. 当用户点击“退出登录”时,会跳转到`LoginActivity`界面,并关闭当前界面。
此外,代码中使用了`SharedPreferences`来保存和获取学生的学号等信息,并使用`Toast`来显示相关提示信息。
主要实现了查询学生信息、修改学生信息和返回主页等功能。在onCreate方法中,通过initView()方法初始化控件,然后通过getNumber()方法获取当前学号,接着调用search()方法查询学生信息并显示在对应的视图中,最后分别设置了返回主页和修改信息的点击事件。
其中,点击"修改信息"按钮时,会获取用户输入的信息并进行判空和判断待填写信息的逻辑,然后调用方法来更新用户信息,并根据更新结果显示相应的提示信息。
1. 初始化视图并设置监听器。
2. 在`show()`方法中,默认显示所有学生的信息。首先通过`UserHelper`对象获取所有学生的列表,并将其传递给`AdminStudentAdapter`适配器,然后将适配器设置给`RecyclerView`控件进行显示。
3. 在`search()`方法中,通过点击搜索按钮查询对应的学生信息。首先获取管理员输入的学号,然后通过`UserHelper`对象根据学号获取对应的学生对象,将其添加到一个新的学生列表中,并将新的列表传递给`AdminStudentAdapter`适配器进行显示。
4. 在`search()`方法中,如果管理员未输入学号,则调用`show()`方法显示所有学生信息。
5. 在`search()`方法中,如果查询结果为空,则显示一个提示信息,并清空适配器中的数据。
此外,在`initView()`方法中,获取了各个控件的引用,并创建了一个`UserHelper`对象来辅助数据库操作。
首先,通过`onCreateView`方法初始化了界面布局,并在`initView`中获取了相关的控件,并设置了点击事件监听。
在`onClick`方法中,针对不同的点击事件进行了处理:
1. 点击个人信息(`llInformation`):弹出自定义对话框用于显示和修改个人信息。
2. 点击发布公告(`llNotice`):跳转到发布公告页面(`AdminNoticeActivity`)。
3. 点击添加学生(`llAddStudent`):跳转到添加学生页面(`AdminAddStudentActivity`)。
4. 点击退出登录(`llExit`):跳转到登录页面(`LoginActivity`),并关闭当前的活动。
整体来说,该页面实现了管理员个人页面的基本功能,包括了界面展示和各种操作的处理。
1. 在`onCreate`方法中,初始化视图并设置点击事件。
2. `clear`方法用于清空当前内容,当点击`btnClear`按钮时,会清空`etTitle`、`etTime`和`etContent`的文本内容。
3. `back`方法用于返回,当点击`imgBack`图片时,会调用`finish`方法关闭当前活动。
4. `showNotice`方法用于显示通知,首先通过`getSharedPreferences`方法获取名为"notice"的`SharedPreferences`对象。
- 如果找到了该对象,就从中获取保存的通知标题、时间和内容,并在界面上显示出来。
- 如果没有找到该对象,则显示默认信息。
5. `publishNotice`方法用于发布通知,当点击`btnPublish`按钮时,会获取输入框中的通知标题、时间和内容,并将它们存储在名为"notice"的`SharedPreferences`对象中。
最后,会显示一个提示用户通知发布成功的`Toast`消息。
- 绑定返回按钮的点击事件,点击返回按钮会关闭当前活动。
- 绑定添加按钮的点击事件,点击添加按钮会将用户输入的学生信息插入数据库。
- 获取用户输入的学生信息,并进行信息完整性检查。
- 查询数据库,检查学生账号是否已存在。如果账号已存在,会显示提示信息。
- 如果账号未添加过,将学生信息插入数据库。
- 添加成功后会清空输入框,并清除性别选择。
到此为止,我们的项目就已经完成了!
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/791522
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。