0

我有一个自定义视图。我正在尝试添加多个数组值。但它只是打印最后一个。例如检查下面的代码。我正在尝试显示 schedulePeriod.scheduleMatchups.get(i)。它有两个值。(获取(0)和获取(1)。它总是获取get(1)的值而不是get(0)。scheduleView.add(返回一个值而不是两者)有人可以帮助我吗?

谢谢你

    private ArrayList<View> getScheduleView(final SchedulePeriod schedulePeriod) {
    String teamid = FantasyFootballApplication.getFantasyTeam().teamId;
    View scheduleView = playerRankingsInflate(R.layout.schedule_view);
    ArrayList<View> scheduleViews = new ArrayList<View>();
    for(int i=0; i<schedulePeriod.scheduleMatchups.size(); i++){
        if(!(schedulePeriod.scheduleMatchups.isEmpty())) {
            TextView weekNumber = (TextView) scheduleView.findViewById(R.id.week_number);
            weekNumber.setText(schedulePeriod.scheduleId);

            if(!(teamid.equals(schedulePeriod.scheduleMatchups.get((i)).scheduleAwayTeam.awayTeamId))) {
                TextView scheduleOpp = (TextView) scheduleView.findViewById(R.id.schedule_opp);
                scheduleOpp.setText(schedulePeriod.scheduleMatchups.get(i).scheduleAwayTeam.awayTeamShortName);

                TextView scheduleName = (TextView) scheduleView.findViewById(R.id.schedule_teamname);
                scheduleName.setText(schedulePeriod.scheduleMatchups.get(i).scheduleAwayTeam.awayTeamName);
            } else if(!(teamid.equals(schedulePeriod.scheduleMatchups.get((i)).scheduleHomeTeam.homeTeamId))) {
                TextView scheduleOpp = (TextView) scheduleView.findViewById(R.id.schedule_opp);
                scheduleOpp.setText(schedulePeriod.scheduleMatchups.get(i).scheduleHomeTeam.homeTeamShortName);

                TextView scheduleName = (TextView) scheduleView.findViewById(R.id.schedule_teamname);
                scheduleName.setText(schedulePeriod.scheduleMatchups.get(i).scheduleHomeTeam.homeTeamName);
            }

        }
        scheduleViews.add(scheduleView);
    }



    return scheduleViews;
}
4

1 回答 1

1

正如我所看到的,您只创建一个视图并将其添加到 for 循环中的列表中。因此,您只编辑此视图,您会在 scheduleMatchups 中看到最后一个值。你想把你的

View scheduleView = playerRankingsInflate(R.layout.schedule_view);

在 for 循环中,然后根据更改每个视图并将其添加到您的列表中。

希望这对您有所帮助并享受您的工作。

于 2013-05-16T21:31:20.880 回答