目标
每 X 秒需要更新作业和可能的答案。
试图
可能的答案已使用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;
}
结果
尽管分配更新并且radioGroupPossibleAnswers
每 10 秒调用一次(图 1)并且可能的答案会更新(图 2),但可能的答案保持不变。
图 1:每radioGroupPossibleAnswers
十秒调用一次
图 2:可能的答案每十秒更新一次