首页 > 其他分享 >5.10

5.10

时间:2024-06-14 19:03:49浏览次数:8  
标签:answerRadioGroup questionTextView private 5.10 import totalScore android

今日学习情况总结

与小组成员讨论如何完善咨询中的自我测试页面的测试

代码行量:154行

学习所花时间:1h

 

 

package com.example.memosystem.activity;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.example.memosystem.R;

public class yiyuceshi extends AppCompatActivity {

// 问题数组和对应分值数组
private String[] questions = {
"我感到消沉和无助",
"我对未来感到毫无希望",
"我觉得自己毫无价值",
"我失去了对生活的兴趣",
"我常常感到疲倦和缺乏精力",
"我睡眠不好或者睡眠过多",
"我食欲有明显改变",
"我情绪容易波动,经常感到焦虑或不安",
"我注意力不集中,记忆力下降",
"我有自杀念头或计划",
"我在过去两周内有过精神疲劳或无法集中精力的问题",
"我感到无助和孤独,缺乏人际关系",
"我感到控制不了自己的情绪",
"我心情低落和消沉,无法从中恢复",
"我对生活失去信心和动力?"
};

private int[][] scores = {
{1,0},
{1,0},
{1,0},
{1,0},
{1,0},
{1,0},
{1,0},
{1,0},
{1,0},
{2,0},
{1,0},
{1,0},
{1,0},
{1,0},
{1,0},
};

private int currentQuestionIndex = 0;
private int totalScore = 0;

// Define SharedPreferences key for storing total score
private static final String SCORE_KEY = "SCORE_KEY";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_yiyuceshi);

// Load the total score from SharedPreferences
SharedPreferences sharedPref = getPreferences(MODE_PRIVATE);
totalScore = sharedPref.getInt(SCORE_KEY, 0);

final TextView questionTextView = findViewById(R.id.questionTextView);
final RadioGroup answerRadioGroup = findViewById(R.id.answerRadioGroup);
final Button submitButton = findViewById(R.id.submitButton);

// Show the first question
showQuestion(questionTextView, answerRadioGroup);

submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int selectedRadioButtonId = answerRadioGroup.getCheckedRadioButtonId();
if (selectedRadioButtonId != -1) {
RadioButton selectedRadioButton = findViewById(selectedRadioButtonId);
int selectedAnswerIndex = answerRadioGroup.indexOfChild(selectedRadioButton);
totalScore += scores[currentQuestionIndex][selectedAnswerIndex];
currentQuestionIndex++;
if (currentQuestionIndex < questions.length) {
showQuestion(questionTextView, answerRadioGroup);
} else {
showResult();
}

// Save the updated total score to SharedPreferences
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(SCORE_KEY, totalScore);
editor.apply();
}
}
});
}

private String[][] options = {
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
{"是", "否"},
};

private void showQuestion(TextView questionTextView, RadioGroup answerRadioGroup) {
questionTextView.setText(questions[currentQuestionIndex]);
answerRadioGroup.removeAllViews(); // Clear previous options

// Add options for the current question
for (String optionText : options[currentQuestionIndex]) {
RadioButton radioButton = new RadioButton(this);
radioButton.setText(optionText);
answerRadioGroup.addView(radioButton);
}
}

private void showResult() {
String resultText;
if (totalScore >= 0 && totalScore <= 5) {
resultText = "情绪状态稳定,没有出现明显的抑郁倾向。";
} else if (totalScore >= 6 && totalScore <= 10) {
resultText = "可能存在一定程度的抑郁症状,建议密切关注情绪波动并积极寻求支持与辅导。";
} else {
resultText = "存在明显的抑郁倾向,建议寻求专业心理咨询或心理治疗,以获得更深层次的支持和帮助。";
}

// Display the result on screen
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("抑郁测试评估结果");
builder.setMessage(resultText);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do nothing, just close the dialog
}
});
builder.show();
}
}

标签:answerRadioGroup,questionTextView,private,5.10,import,totalScore,android
From: https://www.cnblogs.com/tianpeisen/p/18248440

相关文章

  • 5.10
    <?xmlversion="1.0"encoding="utf-8"?><ScrollViewxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.androi......
  • 5.10
    与小组成员讨论如何完善咨询中的自我测试页面的测试代码行量:159行学习所花时间:1h   packagecom.example.memosystem.activity;importandroid.content.DialogInterface;importandroid.content.SharedPreferences;importandroid.os.Bundle;importandroid.view.View;im......
  • 5.10
    要求编程输出如下图示的字符分形图形(谢宾斯基三角形),要求提交源代码文件,其中源代码要求逐行注释。importturtle#定义绘制谢宾斯基三角形的函数defdraw_sierpinski_triangle(t,order,size):#递归结束条件:如果order为0,则绘制一个等边三角形iforder==0:......
  • 万兴全能格式转换器v15.5.10.97绿色版
    软件介绍万兴全能格式转换器,又叫万兴优转,国产全能音视频格式转换解决方案。具有音视频格式转换、合并视频、压缩视频、录制视频、下载视频、DVD刻录等功能。以超快的转换速度及强大的功能在国外名声大噪,转换速度是市面同类产品的30倍,操作简便,支持158种视频格式无损转换,批量转......
  • 2024.5.10(周五)总结
    【题目描述】所谓LRU算法,是指在发生缺页并且没有空闲主存块时,把最近最少使用的页面换出主存块,腾出地方来调入新页面。问题描述:一进程获得n个主存块的使用权,对于给定的进程访问页面次序,问当采用LRU算法时,输出发生的缺页次数。【练习要求】请给出源代码程序和运行测试结果,源代码程序......
  • 5.10T2
    给定一个01串,Alice和Bob轮流选择一个"01"子序列进行删除,Alice想要尽可能多,Bob想要尽可能少。求进行多少轮(要求整轮)。Alice一定会删相邻的,Bob一定会删首尾。正常做只能贪心,发现贪不动。然后最优化问题,有单调性,不妨考虑二分为\(k\)。判断根据贪心思想发现只需要保留前......
  • 2024.05.10
    所花时间(包括上课): 1 h左右代码量(行): 200  左右搏客量(篇):1了解到的知识点: ref和reactive备注(其他): ref和reactivereactive在修改响应式对象的时候,要用Object.assign(car,{brand:'xiaomi',price:20})需要一个基本类型的响应式数据,必须使......
  • 5.10
    IPv6vs.IPv4我一直对IPv6这个名字感到困惑,因为我觉得IPv4名字来源于它用来表示32位的四个字节,所以IPv6应该被称为IP16。但实际上,这只是协议的版本号。在IPv4推出之前,曾存在过IPv1、IPv2和IPv3,它们主要用于内部研究IP协议,后来被我们现在的IPv4所取代。在上世纪80年代,还提出过IP......
  • 5.10洛谷收获
    1.求幂函数#includepow(a,b);计算a的b次幂2.error:invalidtypes'int[int]'forarraysubscript|记住这个错误吧,犯过好多次了数组变量名不一致或者是没定义数组空间不够变量名和数组名重复定义3.快速幂快速幂本质上是一个倍增问题,比如说要求6的34次方如果34个6相乘......
  • 5.10
    jetpackcompose主题设计funEmailDetailAppBar(email:Email,isFullScreen:Boolean,modifier:Modifier=Modifier,onBackPressed:()->Unit){TopAppBar(modifier=modifier,title={Column(......