title: android - custom function called before onCreateView
body: <p>I have an activity and inside it a fragment, where i'm trying to display a gridview with pictures.</p>
  
  <p>If I try to access the view in onCreateView() of the fragment, i do get a non-null handler and all is OK :</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      View v = inflater.inflate(R.layout.bar_pics_grid, container, false);
      GridView gridview = (GridView) v.findViewById(R.id.gridview);
      return v;
  </code></pre>
  
  <p>However, since i need to get data from a DB first, so I access the gridview in a custom function :</p>
  
  <pre><code>public void loadData(Bar bar) {
  
      if (showBarDetails.getBar() != null) {
  
          bar = showBarDetails.getBar();
          GridView gridview = (GridView) getView().findViewById(R.id.gridview);
          barImageArray = bar.getImages().toArray(new BarImage[bar.getImages().size()]);
          gridview.setAdapter(new PicsAdapter(showBarDetails, barImageArray));
  
      }
  }
  </code></pre>
  
  <p>In the latter case, gridview is always null, which means this function is called before onCreateView - any ideas why is this happening ?</p>
  
  <p>I initialize the Fragment in the activity's onCreate function as follows :</p>
  
  <pre><code>picsFragment = new PicsFragm(this);
  </code></pre>
  
  <p>Then I have an AsyncTask pulling data from the DB where I call :</p>
  
  <pre><code>@Override
  protected void onPostExecute(AsyncTaskResult&lt;Bar&gt; result) {
  
      if (result.getError() == null) {
          sbd.setBar(result.getResult());
          if (sbd.getPicsFragment().isResumed())
              sbd.getPicsFragment().loadData(sbd.getBar());
      } 
  }
  </code></pre>
  
  <p>Many thanks</p>