In my application i want add some data from server into adapter of RecyclerView
.
I write below codes and i can get data from server and show into RecyclerView
.
But my json in not sorted with Alphabet from server.
I want before add this data into ArrayList
, first sort this with Alphabet and add into ArrayList
.
My json :
{
"validationCheckResult": {
"isValid": true,
"message": "Success"
},
"internalCarBoard": [{
"id": 0,
"name": “S500”,
"companyName": “Benz”,
}, {
"id": 0,
"name": " E250”,
"companyName": “Benz”,
}, {
"id": 0,
"name": “TT”,
"companyName": “Audi”,
}, {
"id": 0,
"name": " Talisman”,
"companyName": “Renult”,
}, {
"id": 0,
"name": " Accord”,
"companyName": “Honda”,
}, {
"id": 0,
"name": “A8”,
"companyName": “Audi”,
}]
}
I want sort above json from companyName with Alphabet before add to ArrayList
.
But i want sort this into Android not server.
My Java codes:
public class SortListActivity extends AppCompatActivity {
private RecyclerView sortList_recycler;
private SortAdapter sortAdapter;
private List<InternalCarBoard> model = new ArrayList<>();
private API api;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sort_list);
sortList_recycler = findViewById(R.id.sortList_recycler);
api = ApiClient.getClient().create(API.class);
sortAdapter = new SortAdapter(model);
sortList_recycler.setHasFixedSize(true);
sortList_recycler.setLayoutManager(new LinearLayoutManager(this));
sortList_recycler.setAdapter(sortAdapter);
Call<VersionUpdateResponse> call = api.getCar();
call.enqueue(new Callback<VersionUpdateResponse>() {
@Override
public void onResponse(Call<VersionUpdateResponse> call, Response<VersionUpdateResponse> response) {
if (response.isSuccessful()) {
if (response.body() != null) {
if (response.body().getInternalCarBoard().size() > 0) {
model.clear();
model.addAll(response.body().getInternalCarBoard());
sortAdapter.notifyDataSetChanged();
}
}
}
}
@Override
public void onFailure(Call<VersionUpdateResponse> call, Throwable t) {
}
});
}
}
How can i sort json with Alphabet from companyName before add into ArrayList
?