问题
This is the json response I am recieving:
[
{
"id": "1",
"sports": "Cricket",
"name": "Suraj"
"year": "2017",
"rank": "1",
"age": "25",
},
{
"id": "2",
"sports": "Cricket",
"name": "Rajeev"
"year": "2017",
"rank": "2",
"age": "24",
},
{
"id": "3",
"sports": "Cricket",
"name": "Kiran"
"year": "2015",
"rank": "1",
"age": "25",
},
{
"id": "4",
"sports": "Badminton"
"name": "Shekhar"
"year": "2017",
"rank": "1",
"age": "22",
},
{
"id": "5",
"sports": "Badminton"
"year": "2017",
"name": "Karan"
"rank": "2",
"age": "22",
},
{
"id": "6",
"sports": "Cricket",
"name": "Ali"
"year": "2017",
"rank": "3",
"age": "26",
}
]
I need to represent this information in a table after grouping it according to the sports type, then again sub group it into years, as in the picture I have attached. But I have no idea how to do that. Can someone help me with this ?
I have created this model class:
public class prev_data {
private String id;
private String sports;
private String name;
private String year;
private String rank;
private String age;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSports() {
return sports;
}
public void setSports(String sports) {
this.sports = sports;
}
....
}
And this is how I am calling the api through retrofit:
List<prev_data> prevList;
Call<List<prev_data>> call3 = apiInterface.getPrev_data();
call3.enqueue(new Callback<List<prev_data>>() {
@Override
public void onResponse(Call<List<prev_data>> call3, Response<List<prev_data>> response3) {
prevList= response3.body();
}
@Override
public void onFailure(Call<List<prev_data>> call3, Throwable t) {
}
});
Any help will be highly appreciated and acknowledged.
来源:https://stackoverflow.com/questions/64252837/how-to-group-api-response-in-android