我正在使用改造来根据其设备填充我的清单活动。数据在 json 文件中。
我确实尝试过这种方法来填充数据,但是只要有类似的类别,它就会填充两次。例如 {Equipment1, checklist1, date1, activity1}, {Equipment1, checklist2, date2, activity2},它会用不同的清单相应地填充 Equipment1 两次。
下图显示了 DP-03 应该只出现一次并且这 2 个数据需要在一个卡片视图中的错误。
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();
}