我可以轻松地从onPostExecute获取responseString值。
但我还添加了 LinkedList<在doInBackground中显示答案列表的CompoundButton> 。
1-如何使用 LinkedList< CompoundButton> 与 onPostExecute ? (比如我的responseString)?
我在下面写的代码给了我错误。是因为我没有使用它们的返回值,还是它们错了?public final class Quiz extends Activity {
RadioGroup rg;
RadioButton rb;
public class FetchTask extends AsyncTask<Integer, Void, String> {
private LinkedList<CompoundButton> answers;
public FetchTask(TextView outputTxt) {
outTxt = outputTxt;
}
protected String doInBackground(Integer... uri) {
responseString = this.qz.getCurrentQuestion().getQuestionText();
this.answers = new LinkedList<CompoundButton>();
for (final Answer ans : this.qz.getCurrentQuestion().getAnswers()) {
this.answers.add(rb);
this.answers.getLast().setText(ans.getAnswerText());
this.answers.getLast().setId(ans.getAnswerId());
this.answers.getLast().setChecked(this.userAnswers.get(ans.getAnswerId()));
this.answers.getLast()
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@SuppressWarnings("synthetic-access")
@Override
public void onCheckedChanged(final CompoundButton buttonView,
final boolean isChecked) {
for (final View rb : FetchTask.this.answers)
{
((CompoundButton) rb).setChecked(false);
}
buttonView.setChecked(isChecked);
}
});
rg.addView(this.answers.getLast());
}
FetchTask.ll.addView(rg);
return responseString;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
outTxt.setText(result);
}
}
}