我有一个名为Score的对象,我在ArrayAdapter中使用它。如何调用其中定义的函数?以下是我的主要活动,包括我试图解决的问题。
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;
}
}
答案 0 :(得分:1)
allScore.set(i,listScore.getScoreTotal(i)); // this is the line I'm working on
使用列表的get()
方法:
allScore.set(i, listScore.get(i).getScoreTotal());
(技术上,listScore
是List而不是ArrayAdapter。)