I am making an application in which I am receiving some JSON data from url as shown in this Image. Basically every date array has 5 objects in it and I am using this piece of code to get the session from and session to values from each date array
JSONObject jsonObject = new JSONObject(response);
JSONObject dataObj = jsonObject.getJSONObject("data");
Iterator<String> iter = dataObj.keys();
while (iter.hasNext()) {
key = iter.next();
JSONArray datesArray = dataObj.getJSONArray(key);
sessionsfrom = new ArrayList<String>();
JSONObject datesObjectt = datesArray.getJSONObject(4);
for (int i = 0; i < datesArray.length(); i++) {
JSONObject datesObject = datesArray.getJSONObject(i);
sessionsfrom.add(datesObject.getString("session_from") + " - " +datesObject.getString("session_to") );
mBaseRecyclerAdapter.setItems(sessionsfrom);
}
In the last line I am storing all the session from and session to values in arraylist and put in adapter of recycler view. These sessions are creating time slots in the app as shown in this Image Now what I want is that I have to save bookingFound value from json to somewhere with session from and session to value i.e. it doesnot show in app but in the background of each slot, every value of bookingFoung must be stored so that when populating viewholder I can check which bookingFound slots return true and which return false so that I can change the color of slots to grey if bookingFound true
To populate view holder I have the following piece of code
private BaseRecyclerAdapter<String, CourtDetailsTimeViewHolder> mBaseRecyclerAdapter = new BaseRecyclerAdapter<String, CourtDetailsTimeViewHolder>(CourtDetailsTimeViewHolder.class, R.layout.item_court_details_availability_time) {
@Override
protected void populateViewHolder(CourtDetailsTimeViewHolder viewHolder, String model, int position) {
// SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
//String name = preferences.getString("slotfound", "");
viewHolder.mCheckBox.setOnCheckedChangeListener(null);
viewHolder.mCheckBox.setText(model);
viewHolder.mCheckBox.setChecked(getChecked(model));
/*for (int i = 0; i < bookingcheck.size(); i++) {
if (bookingcheck.get(i).contains("true")) {
viewHolder.mCheckBox.setEnabled(false);
viewHolder.mCheckBox.setBackgroundResource(R.drawable.slctr_bg_cb_challenges_details_disable);
} else {
viewHolder.mCheckBox.setEnabled(true);
viewHolder.mCheckBox.setBackgroundResource(R.drawable.slctr_bg_cb_challenges_details);
}
}*/
}
};
In this code, the commented part is what I tried but it doesnot worked. I put bookingFound values in bookingcheck arraylist and then checked if it contains true then slots disabled otherwise enabled but it doesnot work... Please Help
Conclusion
1- store bookingFound json value just like session from and session to values
2- use that value to enable or disable slots on the application