Refresh recyclerView with new data Retrofit
<p>I am using Retrofit 2.0 to retrieve data from my api and using a recyclerView to display it.</p>

<p>My main activity has a tab layout and one of those tabs has the recyclerView and the fragment class for that tab is being used to retrieve the data and update the layout.</p>

<p>In my main layout I have a fab which makes a post (all posts are being retrieved in  fragment class) and this fab has it's function of making the post in main activity.</p>

<p>So how can I refresh the layout when the fab's function is over and the post is successfully saved in my database?</p>

<p>Basically 
User clicks fab > Makes his post > Alert dialog closes > recyclerView should be refreshed with new data added.</p>

<p>My Fragment Class : </p>

<pre><code>public class PostsRecentTab extends Fragment {

private static final String TAG = MainActivity.class.getSimpleName();

private RecyclerView feedView;
private ProgressDialog pDialog = MainActivity.pDialog;
LinearLayoutManager layoutManager;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v =  inflater.inflate(R.layout.tab_recent_posts, container, false);

    pDialog.setCancelable(false);
    layoutManager = new LinearLayoutManager(this.getContext());
    feedView = (RecyclerView) v.findViewById(R.id.feedView);

    requestData();

    return v;
}

public void requestData() {
    SocialHubAPI apiService = ApiClient.getClient().create(SocialHubAPI.class);

    pDialog.setMessage("Refreshing...");
    showDialog();

    Call&lt;StatusResponse&gt; call = apiService.getStatuses();
    call.enqueue(new Callback&lt;StatusResponse&gt;() {
        @Override
        public void onResponse(Call&lt;StatusResponse&gt; call, Response&lt;StatusResponse&gt; response) {
            int statusCode = response.code();
            List&lt;Status&gt; statuses = response.body().getStatuses();
            Log.d(TAG, "Status Code: " + statusCode);
            hideDialog();

            updateView(statuses);

        }

        @Override
        public void onFailure(Call&lt;StatusResponse&gt; call, Throwable t) {
            Log.e(TAG, t.toString());
        }
    });
}

private void updateView(List&lt;Status&gt; statuses) {

    StatusesAdapter adapter = new StatusesAdapter(statuses, R.layout.feed_item, getContext());
    feedView.setLayoutManager(layoutManager);
    feedView.setAdapter(adapter);
}

private void showDialog() {
    if (!pDialog.isShowing())
        pDialog.show();
}

private void hideDialog() {
    if (pDialog.isShowing())
        pDialog.dismiss();
}
}
</code></pre>

<p>My Fab On Click : </p>

<pre><code>    FloatingActionButton postStatus = (FloatingActionButton) findViewById(R.id.postStatus);

    postStatus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setTitle("Post Status");

            // Set up the input
            final EditText input = new EditText(MainActivity.this);
            // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
            input.setInputType(InputType.TYPE_CLASS_TEXT);
            builder.setView(input);

            // Set up the buttons
            builder.setPositiveButton("Post", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    postText = input.getText().toString();
                    processPost(postText, sessionManager.getToken());
                    Snackbar.make(view, "Status posted!", Snackbar.LENGTH_LONG).show();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

            builder.show();
        }
    });
</code></pre>

<p>Fab onClick calls this method :</p>

<pre><code>protected void processPost(String postText, String token) {
    SocialHubAPI apiService = ApiClient.getClient().create(SocialHubAPI.class);

    pDialog.setMessage("Posting...");
    showDialog();

    final PostRequest postRequest = new PostRequest();
    postRequest.setStatus(postText);

    Call&lt;PostResponse&gt; call = apiService.postStatus(postRequest, token);
    call.enqueue(new Callback&lt;PostResponse&gt;() {
        @Override
        public void onResponse(Call&lt;PostResponse&gt; call, Response&lt;PostResponse&gt; response) {
            hideDialog();
            Toast.makeText(getApplicationContext(), "Status Posted Successfully!", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onFailure(Call&lt;PostResponse&gt; call, Throwable t) {
            Log.e(TAG, t.toString());
        }
    });
}
</code></pre>