android extra list,如何在Android中使用Intent将对象的ArrayList从一个传递到另一个活动?...

这个博客探讨了一个名为`Question`的Java类,它用于表示数学问题,包括操作数和答案选项。类提供了获取和设置操作数、答案选项以及用户选择的方法,并能检查答案的正确性。在源活动中,通过`QuestionBank`获取问题列表,然后添加新的问题到列表中,并通过Intent在活动间传递。在目标活动中,接收并解析传递的问题列表。
摘要由CSDN通过智能技术生成

275de21597c881e875b9f7dba359052c.png

弑天下

效果很好public class Question implements Serializable {    private int[] operands;    private int[] choices;    private int userAnswerIndex;   public Question(int[] operands, int[] choices) {       this.operands = operands;       this.choices = choices;       this.userAnswerIndex = -1;   }   public int[] getChoices() {       return choices;   }   public void setChoices(int[] choices) {       this.choices = choices;   }   public int[] getOperands() {       return operands;   }   public void setOperands(int[] operands) {       this.operands = operands;   }   public int getUserAnswerIndex() {       return userAnswerIndex;   }   public void setUserAnswerIndex(int userAnswerIndex) {       this.userAnswerIndex = userAnswerIndex;   }   public int getAnswer() {       int answer = 0;       for (int operand : operands) {           answer += operand;       }       return answer;   }   public boolean isCorrect() {       return getAnswer() == choices[this.userAnswerIndex];   }   public boolean hasAnswered() {       return userAnswerIndex != -1;   }   @Override   public String toString() {       StringBuilder builder = new StringBuilder();       // Question       builder.append("Question: ");       for(int operand : operands) {           builder.append(String.format("%d ", operand));       }       builder.append(System.getProperty("line.separator"));       // Choices       int answer = getAnswer();       for (int choice : choices) {           if (choice == answer) {               builder.append(String.format("%d (A) ", choice));           } else {               builder.append(String.format("%d ", choice));           }       }       return builder.toString();     }  }在您的“源活动”中,使用以下命令:  List mQuestionList = new ArrayList;  mQuestionsList = QuestionBank.getQuestions();  mQuestionList.add(new Question(ops1, choices1));  Intent intent = new Intent(SourceActivity.this, TargetActivity.class);  intent.putExtra("QuestionListExtra", ArrayListmQuestionList);在您的目标活动中,使用以下命令:  List questions = new ArrayList();  questions = (ArrayList)getIntent().getSerializableExtra("QuestionListExtra");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值