我对变量 scoretemp 有疑问。它总是返回 0。在 if 条件下它正在工作。
for (final Score score2 : scores) {
scoretemp = score2.getResult();
}
但是当我试图在最后一行得到结果时。
TV2.setText(""+scoretemp);
它总是无缘无故地为零。
代码:
BScore.setOnClickListener(new View.OnClickListener() {
double scoretemp;
public void onClick(View arg0) {
BScore.setVisibility(View.GONE);
sp.play(click, 1, 1, 0 , 0, 1);
int scoreresult = totalscore;
final RequestControllerObserver observer2 = new RequestControllerObserver() {
public void requestControllerDidReceiveResponse(final RequestController requestController) {
// get the scores from our controller
final ScoresController scoresController = (ScoresController) requestController;
final List<Score> scores = scoresController.getScores();
if(scores!=null){
for (final Score score2 : scores) {
scoretemp = score2.getResult();
}
// we're done!
dismissDialog(DIALOG_PROGRESS);
}
}
public void requestControllerDidFail(final RequestController aRequestController, final Exception anException) {
dismissDialog(DIALOG_PROGRESS);
Toast.makeText(getApplicationContext(), "لا يوجد إتصال بالأنترنت أو خطأ في إستقبال البيانات", Toast.LENGTH_LONG).show();
}
};
// set up a ScoresController with our observer
ScoresController scoresController2 = new ScoresController(observer2);
showDialog(DIALOG_PROGRESS);
scoresController2.setMode(mode);
scoresController2.loadRangeForUser(Session.getCurrentSession().getUser());
TV2.setText(""+scoretemp);