首页 > 其他分享 >5.10

5.10

时间:2024-06-11 09:13:09浏览次数:15  
标签:answerRadioGroup resultText private 5.10 import totalScore android

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

代码行量:159行

学习所花时间: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 xinggeceshi extends AppCompatActivity {

// 问题数组和对应分值数组
private String[] questions = {
"在社交活动中,我更喜欢",
"我更倾向于",
"我认为自己更多的是",
"在工作中,我更注重",
"我更喜欢",
"我更倾向于",
"我在生活中更重视",
"我更喜欢",
"当面对冲突时,我更倾向于",
"我更容易被哪种类型的人吸引",
"我更倾向于",
"我更倾向于",
"我在处理问题时更偏向于",
"我更希望自己",
"我更愿意"
};

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

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_xinggeceshi);

// 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 >= 15 && totalScore <= 20) {
resultText = "您可能具有外向、开放、寻求刺激的性格特质,并表现出较高的社交取向和活力。";
} else if (totalScore >= 21 && totalScore <= 30) {
resultText = "您可能具有理性、深思熟虑、冷静分析的性格特征,展现出稳定而务实的思维方式。";
}else if (totalScore >= 31 && totalScore <= 45) {
resultText = "您可能呈现内向、审慎、趋向于稳定和安逸的性格特质,更倾向于独立思考和独处。";
}else if (totalScore >= 46 && totalScore <= 60) {
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,resultText,private,5.10,import,totalScore,android
From: https://www.cnblogs.com/zljzy/p/18241480

相关文章

  • 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(......
  • 2024.5.10家长会发言
    大家好,我是初三四班的学习委员包赟瑞,接下来由我来对半个学期的班级学习情况做一个总结。整体来看,全班的学习态度有一定进步,布置的打卡任务大多能按时完成。但是不能仅仅满足于此,像政治这种需要背诵的学科,许多同学在课下不爱背、不愿背,没有老师监督便开始摆烂,类似这样的不自律行为......
  • Pixelmator Pro 3.5.10 Flare (macOS Universal) - 专业图像编辑工具
    PixelmatorPro3.5.10Flare(macOSUniversal)-专业图像编辑工具Photoshop的卓越替代软件请访问原文链接:PixelmatorPro3.5.10Flare(macOSUniversal)-专业图像编辑工具,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgPixelmatorPro真正基于AppleMac......