0

我有一个在 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;
    }

}
4

1 回答 1

1
allScore.set(i,listScore.getScoreTotal(i)); // this is the line I'm working on

使用 List 的get()方法:

allScore.set(i, listScore.get(i).getScoreTotal());

(从技术上讲,listScore是 List 而不是 ArrayAdapter。)

于 2013-01-13T19:39:55.937 回答