Reputation: 127
I am sending some key and values in volley request params. I am able to send all the data successfully, however, I want to send one of the ArrayList in this format
params.put("facilities", "facilities=1&facilities=3&facilities=7");
I put 1, 3 and 7 as an example This will include the elements that are selected and are in my facilities ArrayList. I have 8 items on the screen and if I select 4 then ArrayList will contain 4 items but how to send in this exact params format? I also tried with the code below but it hasn't worked either
for (int i=0; i<facilitiesList.size(); i++){
params.put("facilities", facilitiesList.get(i).toString());
}
I want to send all the selected data in that format that I showed on top. Anyone knows how to solve this?
EDIT - I select items using the code below
private List<Integer> facilitiesList; ///initialization
private BaseRecyclerAdapter<FacilitiesApi.ApiResponse.Datum, FacilitiesViewHolder> mBaseRecyclerAdapter = new BaseRecyclerAdapter<FacilitiesApi.ApiResponse.Datum, FacilitiesViewHolder>(FacilitiesViewHolder.class, R.layout.layout_list_item_facilities) {
@Override
protected void populateViewHolder(final FacilitiesViewHolder viewHolder, final FacilitiesApi.ApiResponse.Datum model, final int position) {
viewHolder.mCustomCheckBoxFacilities.setText(model.getName());
if (facilitiesList != null) {
if (facilitiesList.contains(model.getId())) {
viewHolder.mCustomCheckBoxFacilities.setChecked(true);
} else {
viewHolder.mCustomCheckBoxFacilities.setChecked(false);
}
}
viewHolder.mCustomCheckBoxFacilities.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
facilitiesList.add(Integer.valueOf(model.getId()));
} else {
facilitiesList.remove(Integer.valueOf(model.getId()));
}
}
});
}
};
Upvotes: 0
Views: 146
Reputation: 5705
You should first create your request String using for loop and then send it in your request. You should do something like this.
String facilities="";
for (int i=0; i<facilitiesList.size(); i++){
if(i==0){
facilities=facilities+"facilities="+facilities.get(i);
}else{
facilities=facilities+"&facilities="+facilities.get(i);
}
}
The i==0
check is required to stop adding & symbol on first position.Try this it should work
Upvotes: 1