0

我在开发一个小型 Android 应用程序时正在学习 Java。我的Question班级定义为:

public class Question {
    private int questionId;
    private int answer;

    public Question (int questionId, int answer) {
        this.questionId = questionId;
        this.answer = answer;
    }

    [...]    //getter-setter

}

res/values/strings.xml我有:

    <string name="Qst1">Question number 1</string>
    <string name="Qst2">Question number 2</string>
    [...]
    <string name="QstN">Question number N</string>
    <bool name="Ans1">true</bool>
    <bool name="Ans2">true</bool>
    [...]
    <bool name="AnsN">false</bool>

然后我创建了一个新类:

public class QuestionsList extends ArrayList {

    public void autofill(){
      // autofill the list with the questions
    }
}

为了获得Question一个对象,我通常调用构造函数如下:

question1 = new Question(R.string.Qst1, R.bool.Ans1)

我想定义方法 autofill以填写文件QuestionsList中定义的所有问题xml 我该如何实施?

4

1 回答 1

2

您可以只使用字符串数组并迭代数组。我认为使用字符串数组将是处理你的问题的一种更安卓的方式。让我知道您是否能够解决您的问题!

于 2020-04-16T14:18:16.740 回答