title: getView problems setting Listener with position
body: <p>I have a <code>ListView</code> with an <code>Adapter</code> that is using a <code>LruCache</code> as it's <code>ViewHolder</code>. I'm attempting to retrieve a <code>View</code> from the cache inside <code>getView()</code> and set a <code>onLongClickListener</code>. However despite my efforts I seem to get the last index in my cache every single time. </p>
  
  <p><strong>Adapter</strong></p>
  
  <pre><code>private class MyAdapter extends BaseAdapter {
          private LruCache&lt;Integer, View&gt; mViewCache;
          private Context mContext;
          private LayoutInflater mInflater;
  
          private MyAdapter(Context context) {
              mContext = context;
              mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              mViewCache = new LruCache&lt;Integer, View&gt;(10);
          }
  
          private View inflateMyView(ViewGroup parent, View view) {
              view = mInflater.inflate(R.layout.my_row, null);
              return view;
          }
  </code></pre>
  
  <p><strong>getView</strong></p>
  
  <pre><code>@Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      View view = mViewCache.get(position);
  
      if (view == null) {
          view = inflateMyView(parent, null);
          mViewCache.put(position, view);
      }
      ...
      ...
  view.setOnLongClickListener(new OnLongClickListener() {
  </code></pre>
  
  <p>So as you can now see my <code>onLongClickListener</code> only works on the last item I added to my list(last index in my cache). I need each item in my list to have this <code>Listener</code> attached, not just the last. Any help is appreciated, I've been staring at this too long. </p>
  
  <p><strong>Edit (FYI)</strong><br>
  Due to the tightly coupled nature of this code the <code>onLongClickListener</code> must remain inside <code>getView</code>. Which is why I'm so frustrated. If this has to move it becomes a totally different solution</p>