title: Content view not yet created in refreshing a list fragment
body: <p><strong>SOLUTION:</strong>
  It was a case of having 2 different instances of WinnersFragment which caused the lv = getListView() to be null on the refresh. </p>
  
  <p>My fragment list view works fine on load.  However when I call public static void InitTask(String searchState).  I get Content view not yet created at lv = getListView().</p>
  
  <p>My goal is to just refresh the listview with new json.  </p>
  
  <p>I have tried calling getlistView in pre execute and I have tried using a new inittask.<br>
  I believe it has something to do with creating a new instance of the WinnersFragment but I am not sure. </p>
  
  <p>I found this <a href="https://stackoverflow.com/questions/12228842/content-view-not-yet-created-on-android-fragments">&quot;Content view not yet Created&quot; on Android Fragments</a>  but while I understand it hitting the main thread I do not understand how to implement the solution to see if that is my issue.</p>
  
  <pre><code> public class WinnersFragment extends ListFragment {
  private static String URL = "http://www.xxx.com/RichardsTesting/winners.json";
  
  Context context;
  Winners_List_Adapter adapter;
  static View v;
  ListView lv;
  ArrayList&lt;String&gt; alFName;
  private ProgressDialog pd;
  private static final String TAG_ID = "id";
  private static final String TAG_FNAME = "fname";
  private static final String TAG_STATE = "state";
  private static final String TAG_CODE = "code";
  private static final String TAG_AMOUNT = "amount";
  
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; winnersList;
  
  JSONArray winners = null;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      v = inflater.inflate(R.layout.winners_list, container, false);
      context = getActivity().getApplicationContext();
      new InitTask().execute();
  
      return v;
  }
  
  @Override
  public void onDestroy() {
      lv.setAdapter(null);
      super.onDestroy();
  }
  
  protected class InitTask extends AsyncTask&lt;Context, Integer, String&gt; {
      @Override
      protected void onPreExecute() {
          pd = new ProgressDialog(v.getContext());
          pd.setTitle("Updating...");
          pd.setMessage("Please wait.");
          pd.setCancelable(false);
          pd.setIndeterminate(true);
          pd.show();
      }
  
      @Override
      protected String doInBackground(Context... params) {
          // Hashmap for ListView
          winnersList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          // Creating JSON Parser instance
          JSONParser jParser = new JSONParser();
  
          // getting JSON string from URL
          String json = jParser.getJSONFromUrl(URL);
          try {
              JSONArray json1 = new JSONArray(json);
  
              // looping through All Contacts
              for (int i = 0; i &lt; json.length(); i++) {
                  JSONObject c = json1.getJSONObject(i);
  
                  // Storing each json item in variable
                  String id = c.getString(TAG_ID);
                  String fName = c.getString(TAG_FNAME);
                  String state = c.getString(TAG_STATE);
                  String code = c.getString(TAG_CODE);
                  String amount = c.getString(TAG_AMOUNT);
  
                  // creating new HashMap
                  HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                  // adding each child node to HashMap key =&gt; value
                  map.put(TAG_ID, id);
                  map.put(TAG_FNAME, fName);
                  map.put(TAG_STATE, state);
                  map.put(TAG_CODE, code);
                  map.put(TAG_AMOUNT, amount);
  
                  // adding HashList to ArrayList
                  winnersList.add(map);
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return "COMPLETE!";
      }
  
      @Override
      protected void onProgressUpdate(Integer... values) {
          super.onProgressUpdate(values);
      }
  
      @Override
      protected void onPostExecute(String result) {
          super.onPostExecute(result);
          // selecting single ListView item
          lv = getListView();
          if (pd != null) {
              pd.dismiss();
          }
          setListWinners();
      }
  }
  
  public void setListWinners() {
      adapter = new Winners_List_Adapter(this.getActivity(), winnersList);
      lv.setAdapter(adapter);
  }
  
  public static void InitTask(String searchState) {
      if (searchState !=null) {
      URL = URL+"?state="+searchState;
      WinnersFragment search = new WinnersFragment();
      search.new InitTask().execute();
      }
  }
  }
  </code></pre>
  
  <p>LOG</p>
  
  <pre><code>12-04 13:01:48.156: E/AndroidRuntime(1367): FATAL EXCEPTION: main
  12-04 13:01:48.156: E/AndroidRuntime(1367): java.lang.IllegalStateException: Content view not yet created
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at com.xxx.xxx.WinnersFragment$InitTask.onPostExecute(WinnersFragment.java:123)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at com.xxx.xxx.WinnersFragment$InitTask.onPostExecute(WinnersFragment.java:1)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at android.os.AsyncTask.finish(AsyncTask.java:631)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at android.os.Handler.dispatchMessage(Handler.java:99)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at android.os.Looper.loop(Looper.java:137)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at android.app.ActivityThread.main(ActivityThread.java:4898)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at java.lang.reflect.Method.invokeNative(Native Method)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at java.lang.reflect.Method.invoke(Method.java:511)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
  12-04 13:01:48.156: E/AndroidRuntime(1367):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>xml</p>
  
  <pre><code>  &lt;ListView
      android:id="@id/android:list"
      android:layout_width="match_parent"
      android:layout_height="0dip"
      android:layout_weight="1"
      android:drawSelectorOnTop="false" /&gt;
  </code></pre>
  
  <p>Calling Fragment code</p>
  
  <pre><code>public class TabsFragmentActivity extends FragmentActivity implements
      FragmentTabHost.OnTabChangeListener, OnClickListener {
        blablabla
  }
  
  @Override
  public void onClick(View v) {
      switch (v.getId()) {
      case R.id.btnDismiss:
          getSupportFragmentManager().popBackStackImmediate();
          break;
      case R.id.ibSearch:
          LayoutInflater inflater = LayoutInflater.from(this);
          final View textenter = inflater.inflate(R.layout.winners_list, null);
          final EditText userinput = (EditText) textenter
                  .findViewById(R.id.etSearchState);
          String searchState = userinput.toString();
          WinnersFragment.InitTask(searchState);
          break;  
      }
  }
  </code></pre>