title: Android SimpleAdapter wrong data-item gets associated with a list row
body: <p>I have a listview with custom SimpleAdapter associated. I made the custom SimpleAdapter because I want to associate a different event handler with the contained textview and the  imageview than the rest of the list-item widgets. So, basically I have two different event handlers for two parts of a list-item.</p>
  
  <p>My SimpleAdapter customization is:  </p>
  
  <pre><code>class ClickableButtonListAdapter extends SimpleAdapter {
  
      private static class ViewHolder {
          TextView text;
          ImageView image;
      }
  
      public ClickableButtonListAdapter(Context context,
          List&lt;? extends Map&lt;String, ?&gt;&gt; data, int resource, String[] from, int[] to) {
          super(context, data, resource, from, to);
      }
  
      @SuppressWarnings("unchecked")
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
          final View view = super.getView(position, convertView, parent);
          ViewHolder holder = (ViewHolder) view.getTag();
          if(holder == null) {
              holder = new ViewHolder();
              holder.text = (TextView) view.findViewById(R.id.comments);
              holder.image = (ImageView) view.findViewById(R.id.arrow);
              view.setTag(holder);
              final Context context = view.getContext();
              final HashMap&lt;String, String&gt; article = (HashMap&lt;String,String&gt;) getItem(position);
              OnClickListener listener = new OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      String item_id = article.get("item_id");
                      Intent intent = new Intent(context, HNewsCommentsActivity.class);
                      intent.putExtra("item_id", item_id);
                      context.startActivity(intent);
                  }
              };
              holder.text.setOnClickListener(listener);
              holder.image.setOnClickListener(listener);
          }
          return view;
      }
  }
  </code></pre>
  
  <p>Later, in my activity onCreate, I associate my custom SimpleAdapter like this:  </p>
  
  <pre><code>    public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          try {
              final ArrayList&lt;HashMap&lt;String, String&gt;&gt; articles = getHNewsFeed();
              final SimpleAdapter adapter = new ClickableButtonListAdapter(this,
                      articles, R.layout.article,
                      new String[] {"title", "urlShort", "score", "comments", "item_id"},
                      new int[] {R.id.title, R.id.url, R.id.score, R.id.comments, R.id.item_id}
                      );
              final ListView l = (ListView) findViewById(android.R.id.list);
              l.setAdapter(adapter);
              l.setOnItemClickListener( new OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {
                      final HashMap&lt;String, String&gt; article = articles.get(position);
                      String url = article.get("url");
                      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                      startActivity(intent);
                  }
              });
          } catch (Exception e) {
              Log.w(TAG, e.getMessage());
              Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
          }
      }
  </code></pre>
  
  <p>My problem is these the event handler associated with the contained textview and imageview (which I initialize in getView of the custom SimpleAdapter) seem to get a wrong data-source item and shows data of a different article upon clicking. The listview item click handler, however, gets the correct data source item. Can somebody help me in pointing out why the event handler I associate with a textview and an imageview in getView of the custom SimpleAdapter does not work correctly? My understanding is 'getItem(position)' method of the SimpleAdapter should be returning the correct data source item. But for some reason, it does not appear to do so. </p>