1

標的

X 秒ごとに、割り当てと可能な回答を更新する必要があります。

試み

可能な回答は、 を使用して Android アプリに追加されましたll.addView(radioGroupPossibleAnswers(params3));

アイデアはradioGroupPossibleAnswers(params3);、更新スレッド内で呼び出すと、ラジオ グループ内の可能な回答が更新されるというものでしたtextView2.setText("" + assignment.getAssignment() + "");

更新スレッド

assignment.setRandomIntegerOneAndTwo(10);

assignmentTextView.setText("" + assignment.getAssignment() + "");

RelativeLayout relativeLayout = new RelativeLayout(this);

relativeLayout.addView(assignmentTextView);
relativeLayout.addView(radioGroupPossibleAnswers(radioGroupLayoutParams));

setContentView(relativeLayout);

Thread t = new Thread() {
    @Override
    public void run() {
        try {
            while (!isInterrupted()) {
                Thread.sleep(10000);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        tenSecondCountDown(countDownTextView);
                        assignment.setRandomIntegerOneAndTwo(10);

                        assignmentTextView.setText(""
                                + assignment.getAssignment() + "");

                        RelativeLayout.LayoutParams params3 = new RelativeLayout.LayoutParams(
                                LayoutParams.WRAP_CONTENT,
                                LayoutParams.WRAP_CONTENT);

                        radioGroupPossibleAnswers(params3);
                    }
                });
            }
        } catch (InterruptedException e) {
        }
    }
};
t.start();

ラジオグループ

private RadioGroup radioGroupPossibleAnswers(
        android.widget.RelativeLayout.LayoutParams p) {
    RadioGroup rg = new RadioGroup(this);
    rg.setOrientation(RadioGroup.VERTICAL);
    rg.setLayoutParams(p);
    ArrayList<Integer> a = assignment.getPossibleAnswers();
    final RadioButton[] rb = new RadioButton[5];
    for (int i = 0; i < assignment.getPossibleAnswers().size(); i++) {
        int possibleAnswer = a.get(i);

        System.out.println("Possible answer: " + a.get(i));

        rb[i] = new RadioButton(this);
        rb[i].setText(a + " " + assignment.getPossibleAnswers().size()
                + " " + i + " " + possibleAnswer);
        rb[i].setId(i);
        rb[i].setTextSize(30);

        rg.addView(rb[i]);
    }
    return rg;
}

結果

10 秒ごとに割り当てが更新され、radioGroupPossibleAnswersが呼び出され (図 1)、可能な回答が更新されます (図 2) が、可能な回答は同じままです。

図1

図 1:radioGroupPossibleAnswers10 秒ごとに呼び出されます

図2

図 2:可能な回答は 10 秒ごとに更新されます

4

0 に答える 0