Reputation: 1858
I have a custom view. I am trying to add multiple arrray values. But its just printing the last one. For instance check the below code. I am trying to dispay schedulePeriod.scheduleMatchups.get(i). It has two values. (get (0) and get (1). Its always getting the value of get(1) not get(0). scheduleView.add ( is returning one value not both) can anyone help me?
Thank You
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;
}
Upvotes: 0
Views: 49
Reputation: 883
As I can see you are creating only one view and adding it to list in for loop. And therefore you are editing only this view and you see last value in your scheduleMatchups. You want to place your
View scheduleView = playerRankingsInflate(R.layout.schedule_view);
inside the for loop and then alter every view according and add it to your list.
Hope this helps and enjoy your work.
Upvotes: 1