public void onRun() { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); list = dbHandler.getDatabyTypeFav(type); List<Data> EmptyList = new ArrayList<Data>(); EmptyList.add( new Data( "No favourite added yet", "", "", "", "", "", "<Description><Desc>Tap on star icon in any event to add it as a favourite...</Desc></Description>", "empty")); if (list != null) mainlist.setAdapter(new ListAdapter(context, -1, list)); else mainlist.setAdapter(new ListAdapter(context, -1, EmptyList)); if (isConnected) { try { con.getDatabaseUpdate(dbHandler.getVersion()); } catch (JSONException e) { e.printStackTrace(); } } else { swipeRefreshLayout.setRefreshing(false); Toast.makeText(context, "Please Connect To The Internet", Toast.LENGTH_SHORT).show(); } }
@Override public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootview = inflater.inflate(R.layout.fragment_home_events, container, false); mainlist = (ListView) rootview.findViewById(R.id.listView); swipeRefreshLayout = (SwipeRefreshLayout) rootview.findViewById(R.id.swipe_refresh_layout); con = new ConnectionManager(getActivity(), swipeRefreshLayout, mainlist, null, type); list = dbHandler.getDatabyTypeFav(type); List<Data> EmptyList = new ArrayList<Data>(); // EmptyList.add(new Data("Nothing To Display","","","","","","<Description><Desc>Please add // Something...</Desc></Description>","empty")); EmptyList.add( new Data( "No favourite added yet", "", "", "", "", "", "<Description><Desc>Tap on star icon in any event to add it as a favourite...</Desc></Description>", "empty")); Log.d("AARUUSH", "onCreateView"); if (list != null) mainlist.setAdapter(new ListAdapter(context, -1, list)); else mainlist.setAdapter(new ListAdapter(context, -1, EmptyList)); mainlist.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { TextView title = (TextView) view.findViewById(R.id.title); if (!title.getText().equals("Nothing To Display") && !title.getText().equals("No favourite added yet")) { Intent intent = new Intent(getActivity(), EventDetails.class); Bundle bundle = list.get(i).getAsBundle(); intent.putExtras(bundle); startActivity(intent); } else { Toast.makeText( getActivity(), "Go to any Domain to see all events", Toast.LENGTH_SHORT) .show(); } } }); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.post( new Runnable() { @Override public void run() { onRun(); } }); return rootview; }