title: Android json viewpager action bar fragmentpageadapter
body: <p>I have created <code>action bar</code> and <code>viewpager</code>, I have three <code>fragment</code>. Each of the <code>fragment</code> I <code>parsed json</code> and can show each <code>listview</code> . My problem is : If I <code>click</code> second <code>fragment</code> and then I go back(<code>click</code> firs <code>fragmet</code>) when I go to the next <code>fragment</code> and then if I go to a front <code>fragment</code> at this situation  Loading information from the <code>server</code> occurs twice, I use <code>AsyncTask</code> class to load info from <code>server</code>.</p>
  
  <p><strong>Below is a my code :</strong></p>
  
  <pre><code>public class TabsPagerAdapter extends FragmentPagerAdapter {
  
  public TabsPagerAdapter(FragmentManager fm) {
      super(fm);
  }
  
  @Override
  public Fragment getItem(int index) {
  
      switch (index) {
      case 0:
  
          return new SendItemsFragment();
      case 1:
  
          return new RecivedItemsFragment();
      case 2:
  
          return new FavoriteItemsFragment();
  
      }
  
      return null;
  }
  
  @Override
  public int getCount() {
  
      return 3;
  }
  
  public class MainActivity extends FragmentActivity implements TabListener {
  
  private ViewPager viewPager;
  private TabsPagerAdapter mAdapter;
  private ActionBar actionBar;
  private String[] tabs = { "test1", "test2", "test3" };
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      actionBar = getActionBar();
      actionBar.setHomeButtonEnabled(false);
      actionBar.setDisplayHomeAsUpEnabled(true);
      actionBar.setDisplayShowHomeEnabled(false);
      actionBar.setDisplayShowTitleEnabled(false);
      actionBar.setIcon(R.color.white);
      actionBar.setDisplayShowTitleEnabled(true);
      Drawable d = getResources().getDrawable(R.drawable.acttitle);
      getActionBar().setBackgroundDrawable(d);
  
      mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
  
      actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
              | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
  
      viewPager = (ViewPager) findViewById(R.id.vp_main);
      viewPager.setAdapter(mAdapter);
  
      getActionBar().setCustomView(R.layout.menu_example);
      actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
              | ActionBar.DISPLAY_SHOW_HOME);
      for (String tab_name : tabs) {
          actionBar.addTab(actionBar.newTab().setText(tab_name)
                  .setTabListener(this));
      }
  
      viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  
          @Override
          public void onPageSelected(int position) {
  
              actionBar.setSelectedNavigationItem(position);
          }
  
          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) {
          }
  
          @Override
          public void onPageScrollStateChanged(int arg0) {
          }
      });
  
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
      // actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
      // R.drawable.background)); background viewpager
  
  }
  
  @Override
  public void onTabReselected(Tab tab, FragmentTransaction ft) {
  }
  
  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {
  
      viewPager.setCurrentItem(tab.getPosition());
  }
  
  @Override
  public void onTabUnselected(Tab tab, FragmentTransaction ft) {
  }
    }
  </code></pre>
  
  <p>This is - one of the fragment's code. Similar to all three of them. The only difference is that the load of data from the server, And also use the AsyncTask class, each of which had a different.</p>
  
  <pre><code>public class SendItemsFragment extends Fragment {
  private String URL = "*******************************************";
  
  public static String KEY_title = "title";
  public static String KEY_description = "description";
  public static String KEY_image = "image";
  public static String KEY_journal = "journal";
  public static String KEY_JournalID = "JournalID";
  public static String KEY_pubDate = "pubDate";
  public static String KEY_statID = "statID";
  public JSONArray jsonarray;
  public ListView list;
  public TransparentProgressDialog pd;
  public JSONParser jsonparser;
  static DealBoxAdapter adapter;
  ProgressDialog pDialog, pDialog1;
  static String fontPath2 = "font.ttf";
  public static Typeface tf2;
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; itemList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  public ImageLoader imageLoader;
  static final int DIALOG_ERROR_CONNECTION = 1;
  private int screenSize;
  private LoadDataAllChanelsToServer loader;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.send_items, container, false);
      list = (ListView) rootView.findViewById(R.id.listView1);
      pd = new TransparentProgressDialog(getActivity(), R.drawable.loader);
      screenSize = getResources().getConfiguration().screenLayout
              &amp; Configuration.SCREENLAYOUT_SIZE_MASK;
      loader=new LoadDataAllChanelsToServer();
  
      loader.execute();
      return rootView;
  }
  
  private class LoadDataAllChanelsToServer extends
          AsyncTask&lt;String, Integer, String&gt; {
  
      @Override
      protected void onPreExecute() {
  
          pd.show();
      }
  
      @Override
      protected String doInBackground(String... urls) {
  
          jsonparser = new JSONParser();
  
          JSONObject jsonobject = jsonparser.getJSONfromURL(URL);
          try {
  
              jsonarray = jsonobject.getJSONArray("data");
  
              for (int i = 0; i &lt; jsonarray.length(); i++) {
                  jsonobject = jsonarray.getJSONObject(i);
  
                  HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                  map.put("journal", jsonobject.getString(KEY_journal));
                  map.put("image", jsonobject.getString(KEY_image));
                  map.put("title", jsonobject.getString(KEY_title));
                  map.put("description",
                          jsonobject.getString(KEY_description));
                  map.put("JournalID", jsonobject.getString(KEY_JournalID));
                  map.put("pubDate", jsonobject.getString(KEY_pubDate));
                  map.put("statID", jsonobject.getString(KEY_statID));
  
                  itemList.add(map);
  
              }
  
          } catch (JSONException e) {
              Log.e("Error", e.getMessage());
              e.printStackTrace();
          }
  
          return itemList.toString();
  
      }
  
      @Override
      protected void onPostExecute(String result) {
          try {
              if (pd != null) {
                  pd.dismiss();
  
              }
          } catch (Exception e) {
  
          }
  
          try {
              adapter = new DealBoxAdapter(getActivity(), itemList,
                      screenSize);
              list.setAdapter(adapter);
  
          } catch (NullPointerException e) {
              e.printStackTrace();
          }
  
      }
  
  }
    }
  </code></pre>
  
  <p>that's all :)
  if anyone knows solution please help me 
  thank you</p>