title: Can't populate layout with JSON data
body: <p>I'm trying to populate a layout of mine by looping through some requested JSON (I use <a href="http://square.github.io/retrofit/" rel="nofollow">Retrofit</a>).</p>
  
  <p>When I try to populate the layout manually (like below), it displays fine:</p>
  
  <pre><code>Post post1 = new Post("1", "1", "This is a message.");
  </code></pre>
  
  <p>But if I try to populate it with the requested JSON data, the layout doesn't get populated nor does it display on my screen. Only the layout with "This is a message." is displayed.</p>
  
  <p>Here is the code within my <code>onCreateView()</code> for my fragment:</p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_main, container, false);
      ListView listView = (ListView) view.findViewById(R.id.listview_posts);
  
      final ArrayList&lt;Post&gt; arrayOfUsers = new ArrayList&lt;Post&gt;();
  
      // This works fine. It populates the layout as it should.
      Post post1 = new Post("1", "1", "This is a message.");
      arrayOfUsers.add(post1);
  
      final RestAdapter restAdapter = new RestAdapter.Builder()
              .setEndpoint(BASE_URL)
              .build();
  
      final ApiEndpointInterface apiService = restAdapter.create(ApiEndpointInterface.class);
  
      apiService.getJsonStuff(1, new Callback&lt;PostData&gt;() {
  
          @Override
          public void success(PostData postData, Response response) {
  
              // This doesn't work either
              Post post2 = new Post("1", "1", "This is a message2.");
              arrayOfUsers.add(post2);
  
              for (Post p : postData.data) {
  
                  // This does not work. The layout isn't populated nor does it display.
                  Post posty = new Post(p.getId(), p.getUserId(), p.getContent());
                  arrayOfUsers.add(posty);
  
                  // The JSON is being read correctly, since this prints out the right values.
                  Log.d("MESSAGE", p.getMessage());
              }
          }
  
          @Override
          public void failure(RetrofitError retrofitError) {
              retrofitError.printStackTrace();
          }
      });
  
      PostAdapter adapter = new PostAdapter(getActivity(), arrayOfUsers);
      listView.setAdapter(adapter);
  
      return view;
  }
  </code></pre>
  
  <p>The callback:</p>
  
  <pre><code>void getJsonStuff(@Path("user_id") int userId, Callback&lt;PostData&gt; response);
  </code></pre>
  
  <p><code>Post</code> model:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  import com.google.gson.annotations.Expose;
  import com.google.gson.annotations.SerializedName;
  
  public class Post {
  
      @Expose
      private String id;
      @SerializedName("user_id")
      @Expose
      private String userId;
      @Expose
      private String content;
  
      public Post(String id, String userId, String content) {
          this.id = id;
          this.userId = userId;
          this.content = content;
      }
  
      /**
       *
       * @return
       * The id
       */
      public String getId() {
          return id;
      }
  
      /**
       *
       * @param id
       * The id
       */
      public void setId(String id) {
          this.id = id;
      }
  
      /**
       *
       * @return
       * The userId
       */
      public String getUserId() {
          return userId;
      }
  
      /**
       *
       * @param userId
       * The user_id
       */
      public void setUserId(String userId) {
          this.userId = userId;
      }
  
      /**
       *
       * @return
       * The content
       */
      public String getContent() {
          return content;
      }
  
      /**
       *
       * @param content
       * The content
       */
      public void setContent(String content) {
          this.content= content;
      }
  
  }
  </code></pre>
  
  <p><code>PostData</code> model:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  import com.google.gson.annotations.Expose;
  
  public class PostData {
  
      @Expose
      public Boolean success;
      @Expose
      public List&lt;Post&gt; data = new ArrayList&lt;Post&gt;();
  
      /**
       *
       * @return
       * The success
       */
      public Boolean getSuccess() {
          return success;
      }
  
      /**
       *
       * @param success
       * The success
       */
      public void setSuccess(Boolean success) {
          this.success = success;
      }
  
      /**
       *
       * @return
       * The data
       */
      public List&lt;Post&gt; getData() {
          return data;
      }
  
      /**
       *
       * @param data
       * The data
       */
      public void setData(List&lt;Post&gt; data) {
          this.data = data;
      }
  
  }
  </code></pre>