мой ответ JSON начинается с массива JSON, который дополнительно содержит три массива. И я хочу отобразить содержимое этих массивов в виде карты. Кажется, что в каждом цикле я всегда меняю один и тот же ViewHolder, поэтому результат всегда будет последним элементом последнего цикла. int i
в onBindViewHolder
указывает положение элемента, который будет показан.
[
{
"firstTeam_VS_secondTeam": [{
"match_id": "248036",
"country_id": "169",
"country_name": "England",
"league_id": "70",
"league_name": "Capital One Cup",
"match_date": "2018-01-24",
"match_status": "FT",
"match_time": "21:00",
"match_hometeam_name": "Arsenal",
"match_hometeam_score": "2",
"match_awayteam_name": "Chelsea",
"match_awayteam_score": "1",
"match_hometeam_halftime_score": "1",
"match_awayteam_halftime_score": "1",
"match_live": "1"
},
.....
],"firstTeam_lastResults": [{
"match_id": "248036",
"country_id": "169",
"country_name": "England",
"league_id": "70",
"league_name": "Capital One Cup",
"match_date": "2018-01-24",
"match_status": "FT",
"match_time": "21:00",
"match_hometeam_name": "Arsenal",
"match_hometeam_score": "2",
"match_awayteam_name": "Chelsea",
"match_awayteam_score": "1",
"match_hometeam_halftime_score": "1",
"match_awayteam_halftime_score": "1",
"match_live": "1"
},
.....
], "secondTeam_lastResults": [{
"match_id": "248036",
"country_id": "169",
"country_name": "England",
"league_id": "70",
"league_name": "Capital One Cup",
"match_date": "2018-01-24",
"match_status": "FT",
"match_time": "21:00",
"match_hometeam_name": "Arsenal",
"match_hometeam_score": "2",
"match_awayteam_name": "Chelsea",
"match_awayteam_score": "1",
"match_hometeam_halftime_score": "1",
"match_awayteam_halftime_score": "1",
"match_live": "1"
},
.....
]
Мой Onbindviewholder
класс, я попробовал этот код, но он отображает тот же набор деталей во всех видах карты
@Override
public void onBindViewHolder(@NonNull footballmatchadapter.ViewHolder viewHolder, int i) {
List<FirstTeamVSSecondTeam> firstTeamVSSecondTeams;
List<FirstTeamLastResult> firstTeamLastResults;
List<SecondTeamLastResult> secondTeamLastResults;
firstTeamVSSecondTeams=post.getFirstTeamVSSecondTeam();
firstTeamLastResults=post.getFirstTeamLastResults();
secondTeamLastResults=post.getSecondTeamLastResults();
viewHolder.tvleague.setText(firstTeamVSSecondTeams.size());
viewHolder.tvhometeamscore.setText(firstTeamLastResults.size());
viewHolder.tvdate.setText(secondTeamLastResults.size());
if(post.getFirstTeamVSSecondTeam()!=null) {
firstTeamVSSecondTeams = post.getFirstTeamVSSecondTeam();
}
if(post.getFirstTeamLastResults()!=null) {
firstTeamLastResults = post.getFirstTeamLastResults();
}
if(post.getSecondTeamLastResults()!=null) {
secondTeamLastResults = post.getSecondTeamLastResults();
}
String leauge="",date="",team1="",team2="",team1score="",team2score="";
if(firstTeamVSSecondTeams!=null)
{
for(FirstTeamVSSecondTeam
firstTeamVSSecondTeam:firstTeamVSSecondTeams)
{
leauge=firstTeamVSSecondTeam.getLeagueName();
date="Match Date "+firstTeamVSSecondTeam.getMatchDate();
team1="Home Team "+firstTeamVSSecondTeam.getMatchHometeamName();
team2="Second Team
"+firstTeamVSSecondTeam.getMatchAwayteamName();
team1score=firstTeamVSSecondTeam.getMatchHometeamName()+" :
"+firstTeamVSSecondTeam.getMatchHometeamScore();
team2score=firstTeamVSSecondTeam.getMatchAwayteamName()+" :
"+firstTeamVSSecondTeam.getMatchAwayteamScore();
viewHolder.tvleague.setText(leauge);
viewHolder.tvdate.setText(date);
viewHolder.tvhometownteam.setText(team1);
viewHolder.tvawayteam.setText(team2);
viewHolder.tvhometeamscore.setText(team1score);
viewHolder.tvawayteamscore.setText(team2score);
}
}
if(firstTeamLastResults!=null)
{
for(FirstTeamLastResult firstTeamLastResult:firstTeamLastResults)
{
leauge=firstTeamLastResult.getLeagueName();
date="Match Date "+firstTeamLastResult.getMatchDate();
team1="Home Team "+firstTeamLastResult.getMatchHometeamName();
team2="Second Team "+firstTeamLastResult.getMatchAwayteamName();
team1score=firstTeamLastResult.getMatchHometeamName()+" :
"+firstTeamLastResult.getMatchHometeamScore();
team2score=firstTeamLastResult.getMatchAwayteamName()+" :
"+firstTeamLastResult.getMatchAwayteamScore();
viewHolder.tvleague.setText(leauge);
viewHolder.tvdate.setText(date);
viewHolder.tvhometownteam.setText(team1);
viewHolder.tvawayteam.setText(team2);
viewHolder.tvhometeamscore.setText(team1score);
viewHolder.tvawayteamscore.setText(team2score);
}
}
if(secondTeamLastResults!=null)
{
for(SecondTeamLastResult SecondTeamLastResult:secondTeamLastResults)
{
leauge=SecondTeamLastResult.getLeagueName();
date="Match Date "+SecondTeamLastResult.getMatchDate();
team1="Home Team "+SecondTeamLastResult.getMatchHometeamName();
team2="Second Team
"+SecondTeamLastResult.getMatchAwayteamName();
team1score=SecondTeamLastResult.getMatchHometeamName()+" :
"+SecondTeamLastResult.getMatchHometeamScore();
team2score=SecondTeamLastResult.getMatchAwayteamName()+" :
"+SecondTeamLastResult.getMatchAwayteamScore();
viewHolder.tvleague.setText(leauge);
viewHolder.tvdate.setText(date);
viewHolder.tvhometownteam.setText(team1);
viewHolder.tvawayteam.setText(team2);
viewHolder.tvhometeamscore.setText(team1score);
viewHolder.tvawayteamscore.setText(team2score);
}
}
}
Это моя ongetItemCount
функция, которая возвращает сумму размеров всех трех массивов
@Override
public int getItemCount() {
int v1 = post.getFirstTeamVSSecondTeam() != null ?
post.getFirstTeamVSSecondTeam().size() : 0;
int v2 = post.getFirstTeamLastResults() != null ?
post.getFirstTeamLastResults().size() : 0;
int v3 = post.getSecondTeamLastResults() != null ?
post.getSecondTeamLastResults().size() : 0;
return v1 + v2 + v3;
}