title: Switching between fragments with grid view afterwards loosing setOnItemClickListener of the gridview
body: <p>I am using fragments to create my gridviews. I also use tabhost to switch between fragments. Currently I have 2 fragments of gridview that I switch between. The problem occur when I switch to the 2nd fragment and then return to the 1st fragment and click the an item in the gridview. My setOnItemClickListener for the 1st gridview fragment doesn't work anymore. The error says a null pointer exception.</p>
  
  <p>Here is my log error:</p>
  
  <pre><code>01-05 16:03:11.521: E/AndroidRuntime(6372): FATAL EXCEPTION: main 
  01-05 16:03:11.521: E/AndroidRuntime(6372): java.lang.NullPointerException
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.content.ComponentName.&lt;init&gt;(ComponentName.java:75)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.content.Intent.&lt;init&gt;(Intent.java:3615)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at com.mayonstudios.onvolo.activities.ExploreFragment$JSONParse$1.onItemClick(ExploreFragment.java:97)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.widget.AdapterView.performItemClick(AdapterView.java:301)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.widget.AbsListView$1.run(AbsListView.java:3973)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.os.Handler.handleCallback(Handler.java:615)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.os.Handler.dispatchMessage(Handler.java:92)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.os.Looper.loop(Looper.java:137)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at android.app.ActivityThread.main(ActivityThread.java:4921)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at java.lang.reflect.Method.invokeNative(Native Method)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at java.lang.reflect.Method.invoke(Method.java:511)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
  01-05 16:03:11.521: E/AndroidRuntime(6372):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>The gridview in my fragment subclass is created using an AsyncTask.
  Here is my fragment gridview codes:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
  
      listExplore = (GridView)getActivity().findViewById(R.id.listviewExplore);
  
      /**
       * Inflate the layout for this fragment
       */
      new JSONParse().execute();
  
      return inflater.inflate(R.layout.custom_list_view, container, false);
  }
  
  /**
   * AsyncTask for Parsing
   */
  private class JSONParse extends AsyncTask&lt;String, String, JSONObject&gt; {
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
      @Override
      protected JSONObject doInBackground(String... args) {
          JSONParser jParser = new JSONParser();
  
          // Getting JSON from URL
          JSONObject json = jParser.getJSONFromUrl(url);
          return json;
      }
      @Override
      protected void onPostExecute(JSONObject json) {
          FeedArray arrayFeed = new FeedArray();
          feedListExplore = arrayFeed.getArrayListFromJSON(json);
          adapter = new CustomFeedAdapter(ExploreFragment.this.getActivity(), feedListExplore, listExplore);
  
          if(listExplore != null){
              new LoadImages().execute();
              listExplore.setAdapter(adapter);
  
              //Set Listener for Items.
              listExplore.setOnItemClickListener(new AdapterView.OnItemClickListener() {    
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                      Intent i = new Intent(getActivity(), PostDetailActivity.class); 
                      ResultsClass itemPost = feedListExplore.get(position);
                      i.putExtra("postObject", itemPost);
                      startActivity(i); 
                  } 
              });
  
          }
      }
  }
  </code></pre>
  
  <p>I am just learning to use fragment now. I think may be the error is related to fragment's life cycle? Should I use onPause and onResume when I switch between fragment so that my setOnItemClickListener will be retained? But I have no idea on how to do it. </p>
  
  <p>Any guidance is greatly appreciated. Thanks in advance.</p>