我有一个在 ArrayAdapter 中使用的名为 Score 的对象。如何调用其中定义的函数?以下是我的主要活动,包括我要修复的线路。
public class ScoreList extends Activity {
private ListView listViewScore;
private Context ctx;
ArrayList<Integer> allScoreChange = new ArrayList<Integer>();
ArrayList<Integer> allScore = new ArrayList<Integer>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.score_list);
ctx = this;
final List<Score> listScore = new ArrayList<Score>();
listScore.add(new Score("Player A", "0", "0"));
listScore.add(new Score("Player B", "0", "0"));
listScore.add(new Score("Player C", "0", "0"));
for(int i = 0; i < listScore.size(); i++)
{
allScoreChange.set(i,0);
allScore.set(i,listScore.getScoreTotal(i)); // this is the line I'm working on
}
}
}
下面是带有函数的 Score 对象本身。
public class Score {
private String name;
private String scoreChange;
private String scoreTotal;
public Score(String name, String scoreChange, String scoreTotal) {
super();
this.name = name;
this.scoreChange = scoreChange;
this.scoreTotal = scoreTotal;
}
public String getScoreTotal() {
return scoreTotal;
}
}