I am using retrofit to populate my checklist activity according to its equipment. The data is in json file.
I did try this method to populate the data but whenever there is similar category, it will populate twice. For example {Equipment1, checklist1, date1, activity1}, {Equipment1, checklist2, date2, activity2}, it will populate Equipment1 twice with different checklist correspondingly.
The image below is shows the bug where DP-03 should only come out once and those 2 data need to be in one cardview.
JSONObject obj = new JSONObject(jresponse);
String count = obj.getString("count");
if(!(count.equals("0")))
{
ArrayList<SectionDataModel> sectionDataModelArrayList = new ArrayList<>();
JSONArray dataArray = obj.getJSONArray("all");
for (int i= 0; i<dataArray.length();i++)
{
SectionDataModel sectionDataModel = new SectionDataModel();
SingleItemDataModel singleItemDataModel = new SingleItemDataModel();
JSONObject dataobj = dataArray.getJSONObject(i);
ArrayList<SingleItemDataModel> singleItemDataModelArrayList = new ArrayList<>();
sectionDataModel.setEqpName(dataobj.getString("Equipment"));
singleItemDataModel.setChecklist(dataobj.getString("Checklists"));
singleItemDataModel.setActivity(dataobj.getString("Activity"));
singleItemDataModel.setStatus(dataobj.getString("Status"));
singleItemDataModel.setTime(dataobj.getString("Date"));
singleItemDataModelArrayList.add(singleItemDataModel);
sectionDataModel.setDescription(singleItemDataModelArrayList);
sectionDataModelArrayList.add(sectionDataModel);
}
// Create RecyclerView Adapter
recyclerViewDataAdapter = new RecyclerViewDataAdapter(getContext(), sectionDataModelArrayList);
// Create the recyclerview
RecyclerView my_recycler_view = view.findViewById(R.id.my_recycler_view);
my_recycler_view.setHasFixedSize(true);
my_recycler_view.setAdapter(recyclerViewDataAdapter);
my_recycler_view.setLayoutManager(new LinearLayoutManager(view.getContext(), LinearLayoutManager.VERTICAL, false));
}
else
{
Toast.makeText(getContext(), "no data", Toast.LENGTH_SHORT).show();
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
//Set Title
builder.setTitle("There is no data available");
builder.setMessage("Please reselect again.");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
} catch (JSONException e) {
e.printStackTrace();
}