package com.maxiee.attitude.ui.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.maxiee.attitude.R;
import com.maxiee.attitude.database.api.GetAllEventApi;
import com.maxiee.attitude.model.Event;
import com.maxiee.attitude.ui.adapter.EventListAdapter;

import org.json.JSONException;

import java.util.ArrayList;

/**
 * Created by maxiee on 15-6-12.
 */
public class EventListFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        RecyclerView rv = (RecyclerView) inflater.inflate(
                R.layout.fragment_event_list, container, false);
        rv.setLayoutManager(new LinearLayoutManager(rv.getContext()));
        try {
            ArrayList<Event> eventList = new GetAllEventApi(getActivity()).exec();
            if (eventList != null) {
                rv.setAdapter(new EventListAdapter(eventList));
            }
        } catch (JSONException e) {e.printStackTrace();}
        return rv;
    }
}

@@ -702,16 +702,57 @@
 ment %7B%0A%0A
+    private RecyclerView mRecyclerView;%0A%0A
     @Ove
@@ -869,16 +869,17 @@
         
+m
 Recycler
@@ -887,11 +887,8 @@
 iew 
-rv 
 = (R
@@ -987,26 +987,37 @@
 e);%0A        
-rv
+mRecyclerView
 .setLayoutMa
@@ -1046,18 +1046,29 @@
 Manager(
-rv
+mRecyclerView
 .getCont
@@ -1072,24 +1072,124 @@
 ontext()));%0A
+        updateEventList();%0A        return mRecyclerView;%0A    %7D%0A%0A    public void updateEventList() %7B%0A
         try 
@@ -1326,18 +1326,29 @@
         
-rv
+mRecyclerView
 .setAdap
@@ -1460,27 +1460,8 @@
 );%7D%0A
-        return rv;%0A
     

use a public method to update list.