1

i just want to leave the message if the List from Json is empty...so how should i do it...getting lots of conflits at recyclerview

A simple {@link Fragment} subclass.

public class TodayFragment extends Fragment implements ViewPager.OnPageChangeListener {

    public static final String URL_DATA =Url.GET_TODAY_UPDATE;
    private RecyclerView recyclerView;
    private RecyclerView.Adapter adapter;
    String currentDate="2017-06-29";
    private List<TodayList> listViews;
    private TextView totalPaidFees;



    public TodayFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/dd");
        loadRecyclerViewData();
        return view;
    }

    private void loadRecyclerViewData() {

        final ProgressDialog progressDialog = new ProgressDialog(getActivity());
        progressDialog.setMessage("Loading...");
        progressDialog.show();

        SingletoneRequst.q(getContext()).add(new StringRequest(Request.Method.GET, URL_DATA+currentDate , new Response.Listener<String>() {


            @Override
            public void onResponse(String response) {
                progressDialog.dismiss();
                Log.i("@url_T","url--"+URL_DATA);
                Log.i("@today", "Json--"+response.toString());
                Gson gson = new Gson();
                TodayFees list = (gson.fromJson(response, TodayFees.class));

                List<TodayList> lists = list.getTodayList();
                for (TodayList todayList : lists) {
                    Log.i("today", "" + todayList);

                }
                totalPaidFees.setText(list.getTotalFees().toString());
                adapter = new Adapter_TodayFees(lists, getContext());
                recyclerView.setAdapter(adapter);


            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                progressDialog.dismiss();
                Toast.makeText(getActivity(), "Network problem!! Check your internet connection", Toast.LENGTH_LONG).show();
            }
        }));

    }




    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
Community
  • 1
  • 1
Sandeep Manmode
  • 395
  • 4
  • 15
  • If you want to show message in the layout where RecyclerView is present refer this [answer](https://stackoverflow.com/questions/28217436/how-to-show-an-empty-view-with-a-recyclerview) – maRShmallow Jul 04 '17 at 07:46

2 Answers2

0

Just check if the Todayfees List has any data. If yes then set the adapter:

if(list != null){
    if(list.size() > 0){
        totalPaidFees.setText(list.getTotalFees().toString());
        adapter = new Adapter_TodayFees(lists, getContext());
        recyclerView.setAdapter(adapter);

    }
    else{
        Toast.makeText(getActivity(), "Data couldn't be fetched properly!", Toast.LENGTH_LONG).show();
    }
}

Hope it helps.

tahsinRupam
  • 6,325
  • 1
  • 18
  • 34
0

Do like that...

List<TodayList> lists = list.getTodayList();
if(lists!=null && lists.size>0){
        for (TodayList todayList : lists) {
            Log.i("today", "" + todayList);

        }
        totalPaidFees.setText(list.getTotalFees().toString());
        adapter = new Adapter_TodayFees(lists, getContext());
        recyclerView.setAdapter(adapter);
}
else{
   //Show the message here
 }
Vishal Chauhan
  • 932
  • 1
  • 6
  • 11