title: Arrayadapter giving the wrong position
body: <p>I've used an activity containing a ViewPager which uses a single fragment which is added dynamically multiple times depending upon the incoming Json Response.</p>
  
  <p>Now my problem is that only in the case when their are way too many items in the list, than after scrolling at times the adapter gives the wrong position when a view is clicked in the list row.</p>
  
  <p>My Fragment containing adapter code is as follows:</p>
  
  <pre><code>    public class FragmentDealDisplay extends Fragment {
          private ListView mDealListView;
          private final String DEAL_ARRAY_TAG = "deals";
          private final String DEAL_CATEGORY_TAG = "category";
          private final String DEAL_ID_TAG = "deal_id";
          private final String DEAL_DESC_TAG = "descripition";
          private final String DEAL_NAME_TAG = "deal_name";
          private final String DEAL_PRICE_TAG = "price";
          private final String DEALER_NAME_TAG = "dealer_name";
          private final String DEAL_IMAGE = "image";
          private ArrayList&lt;DealDataObject&gt; mList;
          private ArrayList&lt;DealDataObject&gt; listToPass;
          TextView mTotalTextView;
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              View view = inflater.inflate(R.layout.fragment_deals, container, false);
              initViewsFragment(view);
              return view;
          }
  
          @Override
          public void onViewCreated(View view, Bundle savedInstanceState) {
              super.onViewCreated(view, savedInstanceState);
              mTotalTextView = (TextView) getView().findViewById(
                      R.id.textView_totalPriceResult);
          }
  
          private void initViewsFragment(View v) {
              mDealListView = (ListView) v.findViewById(R.id.listView_deals);
  
              String jsonFromBundle = getArguments().getString(
                      Constants.DEAL_FRAGMENT_BUNDLE_TAG);
              String category = getArguments().getString(
                      Constants.DEAL_FRAGMENT_BUNDLE_CATEGORY_TAG);
              mList = new ArrayList&lt;DealDataObject&gt;();
              listToPass = new ArrayList&lt;DealDataObject&gt;();
              if (!CommonUtility.isStringEmtyOrNull(jsonFromBundle)) {
                  try {
                      JSONObject jsonObject = new JSONObject(jsonFromBundle);
                      JSONArray jsonArray = jsonObject.getJSONArray(DEAL_ARRAY_TAG);
                      for (int i = 0; i &lt; jsonArray.length(); i++) {
                          JSONObject jObj = jsonArray.getJSONObject(i);
                          if (category.equalsIgnoreCase(jObj
                                  .optString(DEAL_CATEGORY_TAG))) {
                              DealDataObject dataObject = new DealDataObject();
                              dataObject.setDealDescription(jObj
                                      .optString(DEAL_DESC_TAG));
                              dataObject.setDealerId(jObj.optString(DEAL_ID_TAG));
                              dataObject
                                      .setDealerImageUrl(jObj.optString(DEAL_IMAGE));
                              dataObject.setDealerName(jObj
                                      .optString(DEALER_NAME_TAG));
                              dataObject.setDealName(jObj.optString(DEAL_NAME_TAG));
                              dataObject.setDealPrice(jObj.optString(DEAL_PRICE_TAG));
                              mList.add(dataObject);
                          }
                      }
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
  
              }
              FragmentListAdapter fragmentListAdapter = new FragmentListAdapter(
                      getActivity(), R.layout.row_deal_list, mList);
              mDealListView.setAdapter(fragmentListAdapter);
              fragmentListAdapter.notifyDataSetChanged();
          }
  
          public static FragmentDealDisplay newInstance(Bundle b) {
              FragmentDealDisplay dealDisplay = new FragmentDealDisplay();
              Bundle bundle = b;
              dealDisplay.setArguments(bundle);
              return dealDisplay;
          }
  
          private class FragmentListAdapter extends ArrayAdapter&lt;DealDataObject&gt; {
              private ArrayList&lt;DealDataObject&gt; mAdapterList;
  
              public FragmentListAdapter(Context context, int resource,
                      ArrayList&lt;DealDataObject&gt; objects) {
                  super(context, resource, objects);
                  mAdapterList = objects;
              }
  
              @Override
              public int getCount() {
                  return super.getCount();
              }
  
              @Override
              public View getView(int position, View convertView, ViewGroup parent) {
                  View rowView = convertView;
                  ViewHolder holder = new ViewHolder();
                  if (rowView == null) {
                      LayoutInflater inflater = getActivity().getLayoutInflater();
                      rowView = inflater.inflate(R.layout.row_deal_list, null);
  
                      holder.dealerName = (TextView) rowView
                              .findViewById(R.id.textView_dealerName);
                      holder.dealerName.setTag(position);
                      holder.dealDetail = (TextView) rowView
                              .findViewById(R.id.textView_deal_details);
                      holder.dealDetail.setTag(position);
                      holder.dealName = (TextView) rowView
                              .findViewById(R.id.textView_dealName);
                      holder.dealName.setTag(position);
                      holder.dealPrice = (TextView) rowView
                              .findViewById(R.id.textView_dealPrice);
                      holder.dealPrice.setTag(position);
                      holder.dealImage = (ImageView) rowView
                              .findViewById(R.id.imageView_dealer);
                      holder.dealImage.setTag(position);
                      rowView.setTag(holder);
                  } else {
                      holder = (ViewHolder) rowView.getTag();
                  }
                  AQuery aQuery = new AQuery(getActivity());
                  // ViewHolder viewHolder = (ViewHolder) rowView.getTag();
                  DealDataObject dealDataObject = mAdapterList.get(position);
                  holder.dealName.setText(dealDataObject.getDealName());
                  holder.dealerName.setText(dealDataObject.getDealerName());
                  holder.dealPrice.setText(dealDataObject.getDealPrice());
                  if (CommonUtility.isStringEmtyOrNull(dealDataObject
                          .getDealDescription())) {
                  } else {
                      holder.dealerName.append("  --&gt;");
                  }
                  if (!dealDataObject.isSelected()) {
                      holder.dealPrice.setBackgroundColor(getResources().getColor(
                              R.color.castle_grey));
                      listToPass.remove(dealDataObject);
                  } else {
                      holder.dealPrice.setBackgroundColor(getResources().getColor(
                              R.color.blue));
                      listToPass.add(dealDataObject);
                  }
                  holder.dealDetail.setText(Html.fromHtml(dealDataObject
                          .getDealDescription()));
                  aQuery.id(holder.dealImage).image(
                          dealDataObject.getDealerImageUrl(), true, true, 200, 0);
                  final ViewHolder holderTemp = holder;
                  holder.dealerName.setOnClickListener(new OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          if (holderTemp.dealDetail.getVisibility() == View.GONE) {
                              holderTemp.dealDetail.setVisibility(View.VISIBLE);
                          } else {
                              holderTemp.dealDetail.setVisibility(View.GONE);
                          }
                      }
                  });
                  holder.dealPrice.setOnClickListener(new OnClickListener() {
                      @Override
                      public void onClick(View v) {
  //clicking on this textview is supposed to turn the background blue if selected and vice versa
                          int pos = Integer.parseInt(v.getTag().toString());
                          DealDataObject dataObject = mAdapterList.get(pos);
                          if (dataObject.isSelected()) {
                              dataObject.setSelected(false);
                              // v.setBackgroundColor(getResources().getColor(
                              // R.color.castle_grey));
                              listToPass.remove(dataObject);
  
                          } else {
                              dataObject.setSelected(true);
                              // v.setBackgroundColor(getResources().getColor(
                              // R.color.blue));
                              listToPass.add(dataObject);
                          }
                          updateTotal(dataObject);
                          FragmentListAdapter.this.notifyDataSetChanged();
                      }
                  });
                  return rowView;
              }
          }
  
          static class ViewHolder {
              public TextView dealName, dealDetail, dealerName, dealPrice;
              public ImageView dealImage;
          }
  
          private void updateTotal(DealDataObject object) {
              if (getActivity() instanceof DealsActivity) {
                  int currentTotal = 0;
                  String totalInActivity = ((DealsActivity) getActivity())
                          .getTextViewText();
                  if (!CommonUtility.isStringEmtyOrNull(totalInActivity)) {
                      currentTotal = Integer.parseInt(totalInActivity);
                  }
  
                  if (object.isSelected()) {
                      currentTotal = currentTotal
                              + Integer.valueOf(object.getDealPrice());
                  } else {
                      currentTotal = currentTotal
                              - Integer.valueOf(object.getDealPrice());
                  }
                  ((DealsActivity) getActivity()).setTextToTotal(String
                          .valueOf(currentTotal));
                  // mTotalTextView.setText(String.valueOf(currentTotal));
              }
          }
      }
  </code></pre>
  
  <p>now my problem is when I click on the textview </p>
  
  <pre><code>holder.dealPrice.setOnClickListener(new OnClickListener() {
                          @Override
                          public void onClick(View v) {
      //clicking on this textview is supposed to turn the background blue if selected and vice versa
                              int pos = Integer.parseInt(v.getTag().toString());
                              DealDataObject dataObject = mAdapterList.get(pos);
                              if (dataObject.isSelected()) {
                                  dataObject.setSelected(false);
                                  // v.setBackgroundColor(getResources().getColor(
                                  // R.color.castle_grey));
                                  listToPass.remove(dataObject);
  
                              } else {
                                  dataObject.setSelected(true);
                                  // v.setBackgroundColor(getResources().getColor(
                                  // R.color.blue));
                                  listToPass.add(dataObject);
                              }
                              updateTotal(dataObject);
                              FragmentListAdapter.this.notifyDataSetChanged();
                          }
                      });
  </code></pre>
  
  <p>It highlights textview in a different row, for e.g. If I click on the second row it highlights in the 8th and upon debugging the "position" parameter from the getView() method is wrong.</p>
  
  <p>I've gone through various questions and examples regarding the same, any help would be greatly appreciated if you can point out what I've missed.</p>
  
  <p>Please note, this issue happens only when the list contains a lot of data.</p>