title: Android in Tablayout, ViewPager addad again data from JSON to ListView
body: <p>I have four fragment in tablayout with listview each and I fill listview from JSON. So when I slide fragment, for example, see first fragment further see other fragment and when I again return to first fragment I found that the data doubled(or again loaded and add down old listview data).It happens to every fragment. How to make that data is not doubled. I've been doing this program for <a href="http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/" rel="nofollow">http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/</a></p>
  
  <p>This is Fragment1.
      public class Fragment1 extends Fragment {</p>
  
  <pre><code>static final String KEY_ID = "id";
  static final String KEY_TITLE = "title";
  static final String KEY_ARTIST = "artist";
  static final String KEY_DURATION = "duration";
  static final String KEY_THUMB_URL = "thumb_url";
  public static String LOG_TAG = "my_log";
  
  ListView list;
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; songsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  LazyAdapter adapter;
  
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
  
      View rootView = inflater.inflate(R.layout.frag, container, false);
      ParseTask pt = new ParseTask();
      pt.execute();
      Activity ac = new Activity();
  
      list = (ListView) rootView.findViewById(R.id.listView1);
      adapter=new LazyAdapter(getActivity(), songsList);
      list.setAdapter(adapter);
  
  
      list.setOnItemClickListener(
              new OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                          int position, long id) {
                              Intent intent = new Intent(getActivity(), ActivityTwo.class);
                              startActivity(intent);
                  }
              }
      );
  
     return rootView;
  }
  
  
  private class ParseTask extends AsyncTask&lt;Void, Void, String&gt; {
  
      HttpURLConnection urlConnection = null;
      BufferedReader reader = null;
      String resultJson = "";
  
      @Override
      protected String doInBackground(Void... params) {
          // получаем данные с внешнего ресурса
          try {
              URL url = new URL("http://zhaksy-adam.kz/api/Requisitions/GetRequisition");
  
              urlConnection = (HttpURLConnection) url.openConnection();
              urlConnection.setRequestMethod("GET");
              urlConnection.connect();
  
              InputStream inputStream = urlConnection.getInputStream();
              StringBuffer buffer = new StringBuffer();
  
              reader = new BufferedReader(new InputStreamReader(inputStream));
  
              String line;
              while ((line = reader.readLine()) != null) {
                  buffer.append(line);
              }
              resultJson = buffer.toString();
          } catch (Exception e) {
              e.printStackTrace();
          }
          return resultJson;
      }
  
  
      @Override
      protected void onPostExecute(String strJson) {
          super.onPostExecute(strJson);
  
          JSONObject jsonobj = null;
  
          try {
              JSONArray jsonarray = new JSONArray(strJson);
  
              for (int i = 0; i &lt; jsonarray.length(); i++) {
                  HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                  jsonobj = jsonarray.getJSONObject(i);
                  String type = jsonobj.getString("type");
                  if(type.equals("Нужен помощь")) {
  
                      // Adding picture url
                      String img = jsonobj.getString("Picture1");
                      if (img != null) {
                          img = "http://zhaksy-adam.kz" + img;
                          img = img.replace("~/", "/");
                          img = img.replace(" ", "%20");
                      }
  
                      map.put(KEY_ID, jsonobj.getString("ID"));
                      map.put(KEY_TITLE, jsonobj.getString("Title"));
                      map.put(KEY_DURATION, jsonobj.getString("Date"));
                      map.put(KEY_THUMB_URL, img);
  
                      songsList.add(map);
  
                  }
              }
          }catch(JSONException e){
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is my adapter</p>
  
  <pre><code>public class LazyAdapter extends BaseAdapter {
  
  private Activity activity;
  private ArrayList&lt;HashMap&lt;String, String&gt;&gt; data;
  private static LayoutInflater inflater=null;
  public ImageLoader imageLoader;
  MemoryCache memoryCache = new MemoryCache();
  
  public LazyAdapter(Activity a, ArrayList&lt;HashMap&lt;String, String&gt;&gt; d) {
      activity = a;
      data=d;
      inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      imageLoader = new ImageLoader(activity.getApplicationContext());
  }
  
  public int getCount() {
      return data.size();
  }
  
  public Object getItem(int position) {
      return position;
  }
  
  public long getItemId(int position) {
      return position;
  }
  
  public View getView(int position, View convertView, ViewGroup parent) {
      View vi=convertView;
      if(convertView==null)
          vi = inflater.inflate(R.layout.list_row, null);
  
      TextView title = (TextView)vi.findViewById(R.id.title); // title
      TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
      TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
      ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
  
      HashMap&lt;String, String&gt; song = new HashMap&lt;String, String&gt;();
      song = data.get(position);
  
      // Setting all values in listview
      title.setText(song.get(Fragment1.KEY_TITLE));
      artist.setText(song.get(Fragment1.KEY_ARTIST));
      duration.setText(song.get(Fragment1.KEY_DURATION));
      imageLoader.DisplayImage(song.get(Fragment1.KEY_THUMB_URL), thumb_image);
      return vi;
  }
  </code></pre>
  
  <p>}</p>