Я получаю список массивов мониторов холестерина в методе onCreate действия. Я пытаюсь передать его во фрагмент в onPostExecute, но в настоящее время он передается в нулевом списке? В моем onCreate.
cholesterol_monitor= this.getIntent().getParcelableArrayListExtra("monitorList");
CholesterolFragment cholesterolFragment= new CholesterolFragment();
cholesterolFragment.execute(cholesterol_monitor);
В моих методах AsyncTask
private class CholesterolFragment extends AsyncTask<ArrayList<CholesterolMonitor>, Void, ArrayList<CholesterolMonitor>> {
@Override
protected ArrayList<CholesterolMonitor> doInBackground(ArrayList<CholesterolMonitor>... arrayLists) {
cholesterol_monitor=arrayLists[0];
return cholesterol_monitor;
}
@Override
protected void onPostExecute(ArrayList<CholesterolMonitor> result){
cholesterol_monitor= result;
monitorListFragment = MonitorListFragment.newInstance(cholesterol_monitor);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_monitor_layout, monitorListFragment)
.commit();
}
}
РЕДАКТИРОВАТЬ: В моем monitorListFragment
public static MonitorListFragment newInstance(ArrayList<CholesterolMonitor> monitor_list) {
MonitorListFragment fragment = new MonitorListFragment();
Bundle args = new Bundle();
args.putParcelableArrayList(ARG_MONITOR_LIST, monitor_list);
fragment.setArguments(args);
return fragment;
}
РЕДАКТИРОВАТЬ: Потому чтов моем списке нулевые объекты, поэтому я добавил проверку в своем адаптере рециркуляции в списке мониторов, но имена не отображаются?
Это в моем мониторе listrecyclerAdapter
public void onBindViewHolder(final MonitorListRecyclerAdapter.ViewHolder holder, int position) {
if (!(data.get(position).getPatient()== null)){
String patient = "Patient: " + data.get(position).getPatient().getName().get(0).getNameAsSingleString();
String cholesterolLevel = "Cholesterol: "
+ String.format("%.2f", data.get(position).getPatientCholesterolLevel()) + " "
+ data.get(position).getUnitsMeasurement();
holder.patientNameView.setText(patient);
holder.cholesterolView.setText(cholesterolLevel);
}