gpt4 book ai didi

java - 从按钮中选择多个正确答案

转载 作者:行者123 更新时间:2023-12-02 11:38:55 24 4
gpt4 key购买 nike

我的应用程序的游戏屏幕。

Game screen of my application.

大家好,我目前正在开发我的问答应用游戏,其主要机制是每个问题都可能有一个或多个可能的正确答案。到目前为止,我只能从给出的选项中选择一个正确答案。

private Answer getAnswerFromCursor (Cursor cursor){
Answer answer = new Answer();
answer.setAnswerId(cursor.getInt(FIELD_ID_ID));
answer.setQuestionId(cursor.getInt(FIELD_ID_QUESTIONID));
answer.setText(cursor.getString(FIELD_ID_TEXT));

boolean correct = (cursor.getInt(FIELD_ID_CORRECT)==1);
answer.setCorrect(correct);

return answer;
}

boolean 正确值用于设置数据库中的正确答案,其值为 true 设置为 1。

数据库中的正确答案,设为1。

The correct answers in the database, set to 1.

private void displayQuestion(Question question) {

if (question != null) {
answers = answerData.getAnswersbyQuestionId(question.getQuestionId());
List<Integer> myAnswersIndexList = new ArrayList<Integer>();
for (int answerId : answers.keySet()) {
myAnswersIndexList.add(answerId);
}
Collections.shuffle(myAnswersIndexList);
answersFrame.removeAllViews();
questionText.setText(question.getText());

if(answers!=null){
answersButtonsList = new ArrayList<Button>();
Answer answer = null;


for(int answerId : myAnswersIndexList) {

Log.i("Captchabuster", "Adding question with Id " + answerId);
answer = answers.get(answerId);
Button answerButton = new Button(this);
answerButton.setId(answer.getAnswerId());
answerButton.setText(answer.getText());

//handle the button-clicker
answerButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
//timer.cancel();
disableAnswerButtons();
answerButtonClickHandler(v);

}

});

answersButtonsList.add(answerButton);
answersFrame.addView(answerButton, answerButtonLayout);

}
}
}
}

如果选择了选项中的答案并调用answerButtonClickHandler,则 onClick 方法将禁用剩余待回答的答案。

else if(questionId == 8){

importAnswersData(db, questionId, recordData[4], false);
importAnswersData(db, questionId, recordData[6], true);
importAnswersData(db, questionId, recordData[5], false);
importAnswersData(db, questionId, recordData[7], true);
importAnswersData(db, questionId, recordData[8], true);
importAnswersData(db, questionId, recordData[9], true);

}

上面的代码 fragment 展示了如何将答案导入数据库。

public void answerButtonClickHandler(View v)
{
Answer answer = answers.get(v.getId());
if (answer != null) {
questionAnswered++;
if (answer.isCorrect()) {
correctlyAnswered++;

}
/* add template here
v.setBackgroundResource(R.drawable.answer_button_correct);
else{
v.setBackgroundResource(R.drawable.answer_button_wrong);
}*/
questionDescriptionText.setText(question.getDescription());
questionDescriptionText.setVisibility(View.VISIBLE);

if (nextQuestionIndex < questionsIndexList.size()) {
nextBtn.setVisibility(View.VISIBLE);
} else{
completeBtn.setVisibility(View.VISIBLE);
}

}
}

我想不出如何将用户选择的答案与我插入数据库的答案进行比较。

最佳答案

我认为您可以使用 CHeckBoxes 而不是使用按钮,并在某个数组中获取二进制值并将其与数据库值进行比较,我认为从 UI 角度来看这可能更容易、更干净。

关于java - 从按钮中选择多个正确答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48721615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com