Source:
<code>public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_patient_charts, null, false); mEmptyListView = root.findViewById(R.id.vitalEmpty); FontsUtil.setFont(mEmptyListView, FontsUtil.OpenFonts.OPEN_SANS_BOLD); mListView = root.findViewById(R.id.vitalList); mListView.setEmptyView(mEmptyListView); setEmptyListVisibility(false); mListView.setOnItemClickListener((parent, view, position, id) -> { String vitalName = chartsListAdapter.getItem(position); try { JSONObject chartData = observationList.getJSONObject(vitalName); Iterator<String> dates = chartData.keys(); ArrayList<String> dateList = Lists.newArrayList(dates); <START> Boolean validChartData = true; <END> if(dateList.size()==0) ToastUtil.showShortToast(getContext(), ToastUtil.ToastType.ERROR, getString(R.string.data_not_available_for_this_field)); else { JSONArray dataArray = chartData.getJSONArray(dateList.get(0)); String entry = (String) dataArray.get(0); try { Float entryValue = Float.parseFloat(entry); } catch (NumberFormatException e) { validChartData = false; ToastUtil.showShortToast(getContext(), ToastUtil.ToastType.ERROR, getString(R.string.data_type_not_available_for_this_field)); } } if(dateList.size()!=0 && validChartData) { Intent intent = new Intent(getActivity(), ChartsViewActivity.class); Bundle mBundle = new Bundle(); try { mBundle.putString("vitalName", observationList.getJSONObject(vitalName).toString()); } catch (JSONException e) { e.printStackTrace(); } intent.putExtra("bundle", mBundle); startActivity(intent); } } catch (JSONException e) { e.printStackTrace(); } }); return root; }</code><technical_language>need this variable if improve code structure</technical_language>

Target:
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_patient_charts, null, false); mEmptyListView = root.findViewById(R.id.vitalEmpty); FontsUtil.setFont(mEmptyListView, FontsUtil.OpenFonts.OPEN_SANS_BOLD); mListView = root.findViewById(R.id.vitalList); mListView.setEmptyView(mEmptyListView); setEmptyListVisibility(false); mListView.setOnItemClickListener((parent, view, position, id) -> { String vitalName = chartsListAdapter.getItem(position); try { JSONObject chartData = observationList.getJSONObject(vitalName); Iterator<String> dates = chartData.keys(); ArrayList<String> dateList = Lists.newArrayList(dates); if(dateList.size() == 0) ToastUtil.showShortToast(getContext(), ToastUtil.ToastType.ERROR, getString(R.string.data_not_available_for_this_field)); else { JSONArray dataArray = chartData.getJSONArray(dateList.get(0)); String entry = (String) dataArray.get(0); try { Float entryValue = Float.parseFloat(entry); Intent intent = new Intent(getActivity(), ChartsViewActivity.class); Bundle mBundle = new Bundle(); mBundle.putString("vitalName", chartData.toString()); intent.putExtra("bundle", mBundle); startActivity(intent); } catch (NumberFormatException e) { ToastUtil.showShortToast(getContext(), ToastUtil.ToastType.ERROR, getString(R.string.data_type_not_available_for_this_field)); } } } catch (JSONException e) { e.printStackTrace(); ToastUtil.showShortToast(getContext(), ToastUtil.ToastType.ERROR, e.getMessage()); } }); return root; }