title: While displaying data from sqlite database , for every onitemclick same data loads
body: <p>I have written a program to insert json data into sqlite database in the form of a listview which is working perfectly , and with internet on , on every item click the details are also displaying correctly in the next activity.
  But once when the data is loaded and i turn off the internet to load the data through sqlite database , the listview is displaying correctly but on every item click the details on the next activity are always the item which was last viewed.</p>
  
  <pre><code>cursor = listHelper.getAllData();
          String[] columns = new String[] { DbListHelper.ARTWORK_IMAGE, 
                  DbListHelper.WRAPPER_TYPE,
                  DbListHelper.ARTIST_NAME, DbListHelper.COLLECTION_NAME, 
                  DbListHelper.TRACK_NAME,
                  DbListHelper.COLLECTION_PRICE, DbListHelper.TRACK_ID };
  
          int[] to = new int[] { R.id.artworkImage, R.id.wrapperType, 
                  R.id.artistName, R.id.collectionName,
                  R.id.trackName, R.id.collectionPrice, R.id.trackId };
  
          dataAdapter = new CustomImageTextCursorAdapter(getBaseContext(), 
          R.layout.custom_row, cursor, columns, to);
          lv.setAdapter(dataAdapter);
  
  lv.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int 
                  position, long id) {
                  Cursor cursor = (Cursor) parent.getItemAtPosition(position);
                  final int item_id = 
                  cursor.getInt(cursor.getColumnIndex(DbListHelper.UID));
                  String item_content1 = 
                  cursor.getString(cursor.getColumnIndex
                  (cursor.getColumnName(0)));
                  String item_content2 = 
                  cursor.getString(cursor.getColumnIndex
                  (cursor.getColumnName(1)));
                  String item_content3 = 
                  cursor.getString(cursor.getColumnIndex
                  (cursor.getColumnName(2)));
                  String item_content4 = 
                  cursor.getString(cursor.getColumnIndex
                  (cursor.getColumnName(3)));
                  String item_content5 =  
                  cursor.getString(cursor.getColumnIndex
                  (cursor.getColumnName(4)));
                  String item_content6 = 
                  cursor.getString(cursor.getColumnIndex
                  (cursor.getColumnName(5)));
                  String item_content7 =                 
                  cursor.getString(cursor.getColumnIndex
                  (cursor.getColumnName(6)));
                  String item_content8 = 
                  cursor.getString(cursor.getColumnIndex
                  (cursor.getColumnName(7)));
                  Intent intent = new Intent(MainActivity.this, 
                  intent.putExtra("trackId", item_content8);
                  SingleTunesDetails.class);
                  startActivity(intent);
              }
          });
  </code></pre>
  
  <p>CustomImageTextCursorAdapter.java :</p>
  
  <pre><code>public class CustomImageTextCursorAdapter extends SimpleCursorAdapter {
  
  private LayoutInflater mLayoutInflater;
  private Context context;
  private SqliteListHelper listHelper;
  String extStorageDirectory;
  File folder;
  File file;
  ImageLoader imageLoader;
  int layout;
  ConnectionDetector connectionDetector;
  FileCache fileCache;
  
  private class ViewHolder {
      TextView wrapperType, artistName, collectionName, trackName, collectionPrice,trackId;
      ImageView artworkImage;
  
      ViewHolder(View v) {
          wrapperType = (TextView) v.findViewById(R.id.wrapperType);
          artistName = (TextView) v.findViewById(R.id.artistName);
          collectionName = (TextView) v.findViewById(R.id.collectionName);
          trackName = (TextView) v.findViewById(R.id.trackName);
          collectionPrice = (TextView) v.findViewById(R.id.collectionPrice);
          artworkImage = (ImageView) v.findViewById(R.id.artworkImage);
          trackId = (TextView) v.findViewById(R.id.trackId);
          listHelper = new SqliteListHelper(context);
  
          listHelper.open(context);
      }
  }
  
  public CustomImageTextCursorAdapter(Context context, int layout, Cursor c, 
      String[] from, int[] to) {
      super(context, layout, c, from, to);
      this.context = context;
      this.layout = layout;
      mLayoutInflater = LayoutInflater.from(context);
      imageLoader = new ImageLoader(context);
      connectionDetector = new ConnectionDetector(context);
      fileCache = new FileCache(context);
  }
  
  public View newView(Context ctx, Cursor cursor, ViewGroup parent) {
      View itemView = mLayoutInflater.inflate(R.layout.custom_row, parent, 
      false);
      itemView.setTag(new ViewHolder(itemView));
      return itemView;
  }
  
  @Override
  public void bindView(View v, Context context, Cursor c) {
      // you might want to cache these too
      int index = c.getColumnIndex(DbListHelper.UID);
      int cid = c.getInt(index);
      int index0 = c.getColumnIndex(DbListHelper.ARTWORK_IMAGE);
      String cid0 = c.getString(index0);
      int index1 = c.getColumnIndex(DbListHelper.WRAPPER_TYPE);
      String cid1 = c.getString(index1);
      int index2 = c.getColumnIndex(DbListHelper.ARTIST_NAME);
      String cid2 = c.getString(index2);
      int index3 = c.getColumnIndex(DbListHelper.COLLECTION_NAME);
      String cid3 = c.getString(index3);
      int index4 = c.getColumnIndex(DbListHelper.TRACK_NAME);
      String cid4 = c.getString(index4);
      int index5 = c.getColumnIndex(DbListHelper.COLLECTION_PRICE);
      String cid5 = c.getString(index5);
      int index6 = c.getColumnIndex(DbListHelper.TRACK_ID);
      String cid6 = c.getString(index6);
  
      ViewHolder vh = (ViewHolder) v.getTag();
      vh.wrapperType.setText(cid1);
      vh.artistName.setText(cid2);
      vh.collectionName.setText(cid3);
      vh.trackName.setText(cid4);
      vh.collectionPrice.setText(cid5);
      vh.trackId.setText(cid6);
      vh.trackId.setVisibility(View.GONE);
      if (connectionDetector.isConnectingToInternet()) {
          imageLoader.DisplayImage(cid0, vh.artworkImage);
      } else {
          File file = fileCache.getFile(cid0);
          Log.i("TAG", "file_ path :" + file.getPath());
          Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
          vh.artworkImage.setImageBitmap(myBitmap);
      }
  
  }
  </code></pre>
  
  <p>SingleItemDetails.java : In this class i am displaying json data from a url with parameter trackId passed from previous activity.</p>
  
  <pre><code>public class SingleItemDetails extends Activity {
  
  // URL to get contacts JSON
  private static String url = "";
  
  // JSON Node names
  static final String TAG_RESULT = "results";
  static final String TAG_ARTWORK_IMAGE = "artworkUrl100";
  static final String TAG_WRAPPER_TYPE = "wrapperType";
  static final String TAG_ARTIST_NAME = "artistName";
  static final String TAG_COLLECTION_NAME = "collectionName";
  static final String TAG_TRACK_NAME = "trackName";
  static final String TAG_COLLECTION_PRICE = "collectionPrice";
  static final String TAG_TRACK_ID = "trackId";
  
  // contacts JSONArray
  JSONArray tracks = null;
  
  // Hashmap for ListView
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; singleTrackDetails;
  
  String passedData1;
  TextView wrapperTypeText, artistNameText, collectionNameText, trackNameText, 
  collectionPriceText;
  ImageView trackImage;
  String artworkImage, wrapperType, artistName, collectionName, trackName, 
  collectionPrice, trackId;
  
  private SqliteListHelper listHelper;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.single_track);
      singleTrackDetails = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
      wrapperTypeText = (TextView) findViewById(R.id.wrapperType1);
      artistNameText = (TextView) findViewById(R.id.artistName1);
      collectionNameText = (TextView) findViewById(R.id.collectionName1);
      trackNameText = (TextView) findViewById(R.id.trackName1);
      collectionPriceText = (TextView) findViewById(R.id.collectionPrice);
  
      passedData1 = getIntent().getStringExtra("trackId");
  
      listHelper = new SqliteListHelper(getBaseContext());
  
      listHelper.open(getBaseContext());
  
      url = "https://itunes.apple.com/lookup?id=" + passedData1;
  
      // Calling async task to get json
      new GetSingleTrackDetails().execute();
  }
  
  class GetSingleTrackDetails extends AsyncTask&lt;Void, Void, Void&gt; {
      private JSONObject jsonObj;
  
      @Override
      protected Void doInBackground(Void... params) {
          // Creating service handler class instance
          ServiceHandler sh = new ServiceHandler();
  
          // Making a request to url and getting response
          String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
  
          Log.d("Response: ", "&gt; " + jsonStr);
          if (jsonStr != null) {
              try {
                  JSONObject jsonObj = new JSONObject(jsonStr);
  
                  // Getting JSON Array node
                  tracks = jsonObj.getJSONArray(TAG_RESULT);
  
                  // looping through All Products
                  for (int i = 0; i &lt; tracks.length(); i++) {
                      JSONObject c = tracks.getJSONObject(i);
  
                      artworkImage = c.getString("artworkUrl100");
                      wrapperType = c.getString("wrapperType");
                      artistName = c.getString("artistName");
                      collectionName = c.getString("collectionName");
                      trackName = c.getString("trackName");
                      collectionPrice = c.getString("collectionPrice");
                      trackId = c.getString("trackId");
  
                      // tmp hashmap for single contact
                      HashMap&lt;String, String&gt; tunesMap = new HashMap&lt;String, 
                      String&gt;();
  
                      // adding each child node to HashMap key =&gt; value
                      // contact.put(TAG_ID, firstname);
                      tunesMap.put(TAG_ARTWORK_IMAGE, artworkImage);
                      tunesMap.put(TAG_WRAPPER_TYPE, wrapperType);
                      tunesMap.put(TAG_ARTIST_NAME, artistName);
                      tunesMap.put(TAG_COLLECTION_NAME, collectionName);
                      tunesMap.put(TAG_TRACK_NAME, trackName);
                      tunesMap.put(TAG_COLLECTION_PRICE, collectionPrice);
                      tunesMap.put(TAG_TRACK_ID, trackId);
  
                      // adding contact to contact list
                      singleTrackDetails.add(tunesMap);
  
                      long id = listHelper.insertData2(artworkImage, 
                      wrapperType, artistName, collectionName,
                              trackName, collectionPrice, trackId);
  
  
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          } else {
              Log.e("ServiceHandler", "Couldn't get any data from the url");
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
          super.onPostExecute(result);
  
          Cursor cursor = listHelper.getAllData2();
  
          if (cursor.moveToFirst()) {
              do{
              String item_content1 = cursor.getString(cursor.getColumnIndex
              (cursor.getColumnName(0)));
              String item_content2 = cursor.getString(cursor.getColumnIndex
              (cursor.getColumnName(1)));
              String item_content3 = cursor.getString(cursor.getColumnIndex
              (cursor.getColumnName(2)));
              String item_content4 = cursor.getString(cursor.getColumnIndex
              (cursor.getColumnName(3)));
              String item_content5 = cursor.getString(cursor.getColumnIndex
              (cursor.getColumnName(4)));
              String item_content6 = cursor.getString(cursor.getColumnIndex
              (cursor.getColumnName(5)));
              String item_content7 = cursor.getString(cursor.getColumnIndex
              (cursor.getColumnName(6)));
              String item_content8 = cursor.getString(cursor.getColumnIndex
              (cursor.getColumnName(7)));
  
              wrapperTypeText.setText(item_content3);
              artistNameText.setText(item_content4);
              collectionNameText.setText(item_content5);
              trackNameText.setText(item_content6);
              collectionPriceText.setText(item_content7);
              }while(cursor.moveToNext());
          }
          cursor.close();
      }
  
  }
  </code></pre>
  
  <p>Can anyone suggest me where i am going wrong ?
  Thank You</p>