基于Android studio 的个人健康管理系统

发布时间:2024-11-25 06:03

健康的情绪管理有助于个人心理健康 #生活乐趣# #生活情感# #情感话题#

目录

一、实现介绍

视频演示

Get 项目模板源码

非原创 健康饮食管理 :网络资源模板--基于 Android Studio 实现的健康饮食搭配App

一、实现介绍

视频演示

Android studio期末设计大作业~健康管理系统App

1.1 启动页实现

<?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="#fff"

tools:context=".Activity_Public.StartActivity">

<ImageView

android:id="@+id/imageView"

android:layout_width="0dp"

android:layout_height="0dp"

android:src="@drawable/logo"

app:layout_constraintBottom_toTopOf="@+id/view"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.0"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<View

android:id="@+id/view"

android:layout_width="wrap_content"

android:layout_height="60dp"

android:background="#FAFAFA"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent" />

<TextView

android:id="@+id/textView"

android:layout_width="0dp"

android:layout_height="0dp"

android:gravity="center"

android:text="个人健康管理系统"

android:textColor="#000"

android:textSize="20sp"

android:textStyle="bold"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="@+id/view"

app:layout_constraintTop_toTopOf="@+id/view" />

</androidx.constraintlayout.widget.ConstraintLayout>

1.2 注册页面实现

<?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="#fff"

tools:context=".Activity_Public.RegisterActivity">

<LinearLayout

android:id="@+id/linearLayout"

android:layout_width="0dp"

android:layout_height="150dp"

android:gravity="center"

android:orientation="vertical"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent">

<ImageView

android:id="@+id/imageView2"

android:layout_width="match_parent"

android:layout_height="120dp"

app:srcCompat="@drawable/logo" />

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:gravity="center"

android:text="欢 迎 注 册"

android:textColor="#000"

android:textSize="24sp"

android:textStyle="bold" />

</LinearLayout>

<LinearLayout

android:id="@+id/linearLayout2"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_marginStart="24dp"

android:layout_marginTop="16dp"

android:layout_marginEnd="24dp"

android:orientation="vertical"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/linearLayout">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView3"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/phone" />

<EditText

android:id="@+id/et_phone"

android:layout_width="wrap_content"

android:layout_height="30dp"

android:layout_marginLeft="13dp"

android:layout_weight="1"

android:background="#fff"

android:ems="10"

android:hint="请输入手机号码"

android:inputType="phone"

android:textSize="16sp" />

</LinearLayout>

<View

android:id="@+id/view2"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="4dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView4"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/password" />

<EditText

android:id="@+id/et_password"

android:layout_width="wrap_content"

android:layout_height="30dp"

android:layout_marginLeft="13dp"

android:layout_weight="1"

android:background="#fff"

android:ems="10"

android:hint="请输入密码"

android:inputType="textPassword"

android:textSize="16sp" />

</LinearLayout>

<View

android:id="@+id/view3"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="4dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView10"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/password" />

<EditText

android:id="@+id/et_repassword"

android:layout_width="wrap_content"

android:layout_height="30dp"

android:layout_marginLeft="13dp"

android:layout_weight="1"

android:background="#fff"

android:ems="10"

android:hint="请再次输入密码"

android:inputType="textPassword"

android:textSize="16sp" />

</LinearLayout>

<View

android:id="@+id/view4"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="4dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView5"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/name" />

<EditText

android:id="@+id/et_name"

android:layout_width="wrap_content"

android:layout_height="30dp"

android:layout_marginLeft="13dp"

android:layout_weight="1"

android:background="#fff"

android:ems="10"

android:hint="请输入姓名"

android:inputType="textPersonName"

android:textSize="16sp" />

</LinearLayout>

<View

android:id="@+id/view5"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="4dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView6"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/age" />

<EditText

android:id="@+id/et_age"

android:layout_width="wrap_content"

android:layout_height="30dp"

android:layout_marginLeft="13dp"

android:layout_weight="1"

android:background="#fff"

android:ems="10"

android:hint="请输入年龄"

android:inputType="number"

android:textSize="16sp" />

</LinearLayout>

<View

android:id="@+id/view6"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="4dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView7"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/height" />

<EditText

android:id="@+id/et_height"

android:layout_width="wrap_content"

android:layout_height="30dp"

android:layout_marginLeft="13dp"

android:layout_weight="1"

android:background="#fff"

android:ems="10"

android:hint="请输入身高"

android:inputType="number"

android:textSize="16sp" />

</LinearLayout>

<View

android:id="@+id/view7"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="4dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView8"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/weight" />

<EditText

android:id="@+id/et_weight"

android:layout_width="wrap_content"

android:layout_height="30dp"

android:layout_marginLeft="13dp"

android:layout_weight="1"

android:background="#fff"

android:ems="10"

android:hint="请输入体重"

android:inputType="number"

android:textSize="16sp" />

</LinearLayout>

<View

android:id="@+id/view8"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="4dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView9"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/sex" />

<RadioGroup

android:id="@+id/rb_group"

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:orientation="horizontal"

android:text="男" />

<RadioButton

android:id="@+id/rb_woman"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="30dp"

android:text="女" />

</RadioGroup>

</LinearLayout>

<View

android:id="@+id/view9"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="4dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<TextView

android:id="@+id/tv_login"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="16dp"

android:gravity="center|right"

android:text="已有帐号,立即登录!" />

</LinearLayout>

<Button

android:id="@+id/btn_register"

android:layout_width="0dp"

android:layout_height="35dp"

android:background="@drawable/btn_public"

android:text="立 即 注 册"

android:textColor="#fff"

android:textSize="16sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="@+id/linearLayout2"

app:layout_constraintStart_toStartOf="@+id/linearLayout2"

app:layout_constraintTop_toBottomOf="@+id/linearLayout2" />

</androidx.constraintlayout.widget.ConstraintLayout>

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

package com.example.healthmanagementsystem.Activity_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.healthmanagementsystem.Bean.User;

import com.example.healthmanagementsystem.Data.UserDBHelper;

import com.example.healthmanagementsystem.R;

public class RegisterActivity extends AppCompatActivity {

private EditText etPhone;

private EditText etPassword;

private EditText etRepassword;

private EditText etName;

private EditText etAge;

private EditText etHeight;

private EditText etWeight;

private RadioGroup rbGroup;

private RadioButton rbMan;

private RadioButton rbWoman;

private TextView tvLogin;

private Button btnRegister;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_register);

initView();

login();

register();

}

private void login() {

tvLogin.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

finish();

}

});

}

private void register() {

btnRegister.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String phone = etPhone.getText().toString().trim();

String password = etPassword.getText().toString().trim();

String repassword = etRepassword.getText().toString().trim();

String name = etName.getText().toString().trim();

String age = etAge.getText().toString().trim();

String height = etHeight.getText().toString().trim();

String weight = etWeight.getText().toString().trim();

String gender = rbMan.isChecked() ? "男" : "女";

if (phone.isEmpty() || password.isEmpty() || repassword.isEmpty() || name.isEmpty() || age.isEmpty() || height.isEmpty() || weight.isEmpty()) {

Toast.makeText(RegisterActivity.this, "请填写完整信息", Toast.LENGTH_SHORT).show();

return;

}

if (!rbMan.isChecked() && !rbWoman.isChecked()) {

Toast.makeText(RegisterActivity.this, "请选择性别", Toast.LENGTH_SHORT).show();

return;

}

if (userDbHelper.checkIfPhoneNumberExists(phone)) {

Toast.makeText(RegisterActivity.this, "手机号已存在", Toast.LENGTH_SHORT).show();

return;

}

if (!password.equals(repassword)) {

Toast.makeText(RegisterActivity.this, "两次密码输入不一致", Toast.LENGTH_SHORT).show();

return;

}

Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);

Toast.makeText(RegisterActivity.this, "恭喜您,注册成功!", Toast.LENGTH_SHORT).show();

startActivity(intent);

}

});

}

private void initView() {

etPhone = findViewById(R.id.et_phone);

etPassword = findViewById(R.id.et_password);

etRepassword = findViewById(R.id.et_repassword);

etName = findViewById(R.id.et_name);

etAge = findViewById(R.id.et_age);

etHeight = findViewById(R.id.et_height);

etWeight = findViewById(R.id.et_weight);

rbGroup = findViewById(R.id.rb_group);

rbMan = findViewById(R.id.rb_man);

rbWoman = findViewById(R.id.rb_woman);

tvLogin = findViewById(R.id.tv_login);

btnRegister = findViewById(R.id.btn_register);

}

}

1.3 登陆页面实现

<?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="#fff"

tools:context=".Activity_Public.LoginActivity">

<LinearLayout

android:id="@+id/linearLayout"

android:layout_width="0dp"

android:layout_height="200dp"

android:layout_marginTop="24dp"

android:gravity="center"

android:orientation="vertical"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent">

<ImageView

android:id="@+id/imageView2"

android:layout_width="match_parent"

android:layout_height="150dp"

app:srcCompat="@drawable/logo" />

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:gravity="center"

android:text="个人健康管理系统"

android:textColor="#000"

android:textSize="24sp"

android:textStyle="bold" />

</LinearLayout>

<LinearLayout

android:id="@+id/linearLayout3"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_marginStart="24dp"

android:layout_marginTop="50dp"

android:layout_marginEnd="24dp"

android:orientation="vertical"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/linearLayout">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView11"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/phone" />

<EditText

android:id="@+id/editTextPhone"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:layout_marginLeft="15dp"

android:layout_weight="1"

android:background="#fff"

android:ems="10"

android:hint="请输入手机号!"

android:inputType="phone"

android:textSize="16sp" />

</LinearLayout>

<View

android:id="@+id/view11"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="8dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="16dp"

android:gravity="center|left"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView12"

android:layout_width="25dp"

android:layout_height="25dp"

app:srcCompat="@drawable/password" />

<EditText

android:id="@+id/editTextTextPassword"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:layout_marginLeft="15dp"

android:layout_weight="1"

android:background="#fff"

android:ems="10"

android:hint="请输入密码!"

android:inputType="textPassword"

android:textSize="16sp" />

</LinearLayout>

<View

android:id="@+id/view12"

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="8dp"

android:layout_marginTop="8dp"

android:layout_marginRight="8dp"

android:background="#F1F1F1" />

<TextView

android:id="@+id/tv_register"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="16dp"

android:gravity="center|right"

android:text="没有帐号,立即注册!" />

</LinearLayout>

<Button

android:id="@+id/btn_login"

android:layout_width="0dp"

android:layout_height="35dp"

android:layout_marginTop="100dp"

android:background="@drawable/btn_public"

android:text="立 即 登 录"

android:textColor="#fff"

android:textSize="16sp"

app:layout_constraintEnd_toEndOf="@+id/linearLayout3"

app:layout_constraintStart_toStartOf="@+id/linearLayout3"

app:layout_constraintTop_toBottomOf="@+id/linearLayout3" />

</androidx.constraintlayout.widget.ConstraintLayout>

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

package com.example.healthmanagementsystem.Activity_Public;

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.ImageView;

import android.widget.LinearLayout;

import android.widget.TextView;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.healthmanagementsystem.Data.UserDBHelper;

import com.example.healthmanagementsystem.MainActivity;

import com.example.healthmanagementsystem.R;

public class LoginActivity extends AppCompatActivity {

private LinearLayout linearLayout;

private ImageView imageView2;

private TextView textView3;

private LinearLayout linearLayout3;

private ImageView imageView11;

private EditText editTextPhone;

private View view11;

private ImageView imageView12;

private EditText editTextTextPassword;

private View view12;

private TextView tvRegister;

private Button btnLogin;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_login);

initView();

login();

register();

}

private void login() {

tvRegister.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);

startActivity(intent);

}

});

}

private void register() {

btnLogin.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String phone = editTextPhone.getText().toString().trim();

String password = editTextTextPassword.getText().toString().trim();

if (phone.isEmpty() || password.isEmpty()) {

Toast.makeText(LoginActivity.this, "请填写完整信息!", Toast.LENGTH_SHORT).show();

return;

}

UserDBHelper userDbHelper = new UserDBHelper(LoginActivity.this);

boolean isValid = userDbHelper.validateUser(phone, password);

if (isValid) {

SharedPreferences sharedPreferences = getSharedPreferences("User", Context.MODE_PRIVATE);

SharedPreferences.Editor editor = sharedPreferences.edit();

editor.putString("phone", phone);

editor.apply();

Intent intent = new Intent(LoginActivity.this, MainActivity.class);

Toast.makeText(LoginActivity.this, "登陆成功!", Toast.LENGTH_SHORT).show();

startActivity(intent);

} else {

Toast.makeText(LoginActivity.this, "手机号或密码错误!", Toast.LENGTH_SHORT).show();

}

}

});

}

private void initView() {

linearLayout = findViewById(R.id.linearLayout);

imageView2 = findViewById(R.id.imageView2);

textView3 = findViewById(R.id.textView3);

linearLayout3 = findViewById(R.id.linearLayout3);

imageView11 = findViewById(R.id.imageView11);

editTextPhone = findViewById(R.id.editTextPhone);

view11 = findViewById(R.id.view11);

imageView12 = findViewById(R.id.imageView12);

editTextTextPassword = findViewById(R.id.editTextTextPassword);

view12 = findViewById(R.id.view12);

tvRegister = findViewById(R.id.tv_register);

btnLogin = findViewById(R.id.btn_login);

}

}

1.4 首页实现

         在 onCreateView 方法中,初始化了视图并调用了 initView、banner、news 和 search 方法来设置轮播图、显示新闻和搜索功能。

        1.search 方法中,设置了搜索按钮的点击事件处理逻辑,根据输入内容执行搜索操作,并根据搜索结果更新 ListView 的显示。

        2.news 方法中,获取所有新闻并通过 NewsAdapter 将新闻显示在 ListView 上。

        3.banner 方法中,设置了轮播图的图片列表、图片加载器和圆角效果。

        4.initView 方法中,初始化了一些控件并实例化了 NewsHelper 对象用于获取新闻数据。

package com.example.healthmanagementsystem.User;

import android.content.Context;

import android.graphics.Outline;

import android.os.Bundle;

import android.text.TextUtils;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.view.ViewOutlineProvider;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ImageView;

import android.widget.ListView;

import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;

import com.example.healthmanagementsystem.Adapter.NewsAdapter;

import com.example.healthmanagementsystem.Bean.NewsItem;

import com.example.healthmanagementsystem.Data.NewsHelper;

import com.example.healthmanagementsystem.R;

import com.youth.banner.Banner;

import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;

import java.util.List;

public class HomeFragment extends Fragment {

private ListView lv;

private Banner banner;

private NewsAdapter newsAdapter;

private NewsHelper newsHelper;

private EditText etSearch;

private Button btnSearch;

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.fragment_home, container, false);

initView(v);

banner();

news();

search();

return v;

}

private void search() {

btnSearch.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String search = etSearch.getText().toString();

if (TextUtils.isEmpty(search)) {

Toast.makeText(getContext(), "请输入搜索内容", Toast.LENGTH_SHORT).show();

news();

} else {

List<NewsItem> newsItems = newsHelper.searchNewsByTitle(search);

if (newsItems.isEmpty()) {

Toast.makeText(getContext(), "未搜索到相关内容", Toast.LENGTH_SHORT).show();

lv.setAdapter(null);

} else {

newsAdapter = new NewsAdapter(getActivity(), newsItems);

lv.setAdapter(newsAdapter);

}

}

}

});

}

private void news() {

List<NewsItem> newsItems = newsHelper.getAllNews();

newsAdapter = new NewsAdapter(getContext(), newsItems);

lv.setAdapter(newsAdapter);

}

private void banner() {

final List<String> imageUrlList = new ArrayList<>();

imageUrlList.add("https://p2.itc.cn/q_70/images03/20220221/7969492e52604e0f8328a71cd6b1d2e5.png");

imageUrlList.add("https://img2.baidu.com/it/u=3876913131,505484790&fm=253&fmt=auto&app=138&f=JPEG?w=1180&h=492");

imageUrlList.add("https://img.tuguaishou.com/ips_templ_preview/69/1d/29/lg_4187185_1627468002_610130e2a66db.jpg!w1024_w?auth_key=2285688230-0-0-3e7e9b2c72631d954eccff8c10b1de7b");

banner.setImageLoader(new ImageLoader() {

@Override

public void displayImage(final Context context, Object path, ImageView imageView) {

Glide.with(context)

.load(path)

.into(imageView);

}

});

}

private void initView(View v) {

lv = v.findViewById(R.id.lv);

banner = v.findViewById(R.id.banner);

etSearch = v.findViewById(R.id.et_search);

btnSearch = v.findViewById(R.id.btn_search);

newsHelper = new NewsHelper(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"

android:background="#FBFBFB"

tools:context=".User.HomeFragment">

<LinearLayout

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_marginStart="16dp"

android:layout_marginEnd="16dp"

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="140dp"

android:layout_marginTop="8dp" />

<androidx.constraintlayout.widget.ConstraintLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#FBFBFB">

<View

android:id="@+id/view"

android:layout_width="0dp"

android:layout_height="30dp"

android:layout_marginTop="8dp"

android:layout_marginEnd="8dp"

android:layout_marginBottom="8dp"

android:background="@drawable/view_search"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toStartOf="@+id/btn_search"

app:layout_constraintHorizontal_bias="0.533"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<EditText

android:id="@+id/et_search"

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_marginStart="8dp"

android:layout_marginTop="4dp"

android:layout_marginEnd="4dp"

android:layout_marginBottom="4dp"

android:background="#fff"

android:ems="10"

android:hint="请输入查询的标题"

android:inputType="textPersonName"

android:textSize="12sp"

app:layout_constraintBottom_toBottomOf="@+id/view"

app:layout_constraintEnd_toEndOf="@+id/view"

app:layout_constraintStart_toStartOf="@+id/view"

app:layout_constraintTop_toTopOf="@+id/view" />

<Button

android:id="@+id/btn_search"

android:layout_width="70dp"

android:layout_height="20dp"

android:background="@drawable/btn_public"

android:text="查询"

android:textColor="#fff"

app:layout_constraintBottom_toBottomOf="@+id/view"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintTop_toTopOf="@+id/view" />

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView

android:id="@+id/textView2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:text="健康新闻资讯"

android:textColor="#1296db"

android:textSize="16sp"

android:textStyle="bold" />

<ListView

android:id="@+id/lv"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:scrollbars="none" />

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

 1.5 新闻详情页面实现               

        在onCreate方法中初始化页面布局和控件,并调用showreview()、show()、back()和review()方法。

        1.showreview()方法用于显示指定新闻的评论列表,如果评论为空则显示暂无评论提示。

        2.review()方法用于处理用户提交评论的逻辑,包括添加评论到数据库、刷新评论列表,并显示相应的提示信息。

        3.show()方法用于查询并显示指定新闻的详情,包括标题、作者、时间、图片和内容。

        4.back()方法用于返回到主页面的逻辑处理。

        5。initView()方法用于初始化页面控件,并获取新闻id、当前登录用户信息等。

1.6 喝水打卡页面实现

          1. 在`onCreateView`方法中初始化页面布局和控件,调用`initView(v)`方法初始化控件,然后调用`nowtime()`方法获取当前时间,`show()`方法展示用户的饮水信息,`showLv()`方法展示喝水记录,最后设置点击事件监听调用`add()`方法。

        2. `show()`方法根据用户的体重计算目标饮水量,更新显示的目标饮水量和进度,设置不同饮水进度下的背景颜色,更新数据库中的饮水数据。

        3. `add()`方法设置饮水量点击事件监听,每次点击增加200毫升水,更新显示的当前饮水量和进度百分比,更新数据库中的饮水数据,根据进度设置背景颜色,最后调用`showLv()`方法刷新喝水记录。

        4. `nowtime()`方法获取当前时间,并设置时区为北京时间,用于记录喝水时间。

        5. `showLv()`方法展示当天的喝水记录,包括条目数量和倒序显示的喝水时间,使用适配器将数据显示在ListView上。

        6. `initView(View v)`方法初始化页面布局和控件,获取用户手机号并初始化数据库帮助类

1.7 家庭档案页面实现 

该页面用于显示家庭档案信息

1.8 家庭档案详情页面实现

        用于删除修改家庭档案人员信息

1.9 我的页面实现

        在`MineFragment`类中,实现了用户信息展示和相关操作的功能。在`onCreateView`方法中,加载了布局文件并初始化视图,然后依次调用`show()`、`password()`、`information()`和`cut()`方法。

        - `show()`方法用于显示用户信息,包括用户名、手机号、体重、BMI和基础代谢率(BMR)等信息。其中,根据用户的体重、身高、性别和年龄计算了BMI和BMR,并显示在相应的`TextView`中。

        - `information()`方法设置了个人信息点击事件,点击后跳转到`InformationActivity`页面。

        - `password()`方法设置了修改密码点击事件,点击后跳转到`ModifyPasswordActivity`页面。

        - `cut()`方法设置了切换账号点击事件,点击后跳转到`LoginActivity`页面,并关闭当前`Activity`。

        在`initView(View v)`方法中,初始化了布局中的各个`View`对象,并获取了用户手机号码。同时,实例化了`UserDBHelper`对象用于数据库操作。

1.10 修改密码页面实现     

用于修改用户密码

1.11 个人信息页面

用于修改个人信息 

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

Get 项目模板源码

快捷获取方式

网址:基于Android studio 的个人健康管理系统 https://www.yuejiaxmz.com/news/view/252003

相关内容

基于安卓android studio 的 菜谱食谱APP设计
Android日程管理系统实训报告.docx资源
基于安卓Android的健康饮食系统APP(源码+文档+部署+讲解)
android基于饮食健康管理app
基于Android的个人财务管理系统的设计与实现.
Android Studio实现简单的健身系统
基于android的个人健康助理设计与实现(论文)
基于Android studio的二手交易平台
基于Android平台的记事本软件(Android Studio项目+报告+app文件)
基于ESP32的智能家庭健康系统

随便看看