manual merge a7ce913d3b55de6e5808e8b29e50e186a2d4e96a

Change-Id: Iae7405f8aaf90d08172ed9c199783bd0ec37dbf4
diff --git a/src/com/android/mms/ui/ConversationList.java b/src/com/android/mms/ui/ConversationList.java
index f0350e4..cc3c3f5 100644
--- a/src/com/android/mms/ui/ConversationList.java
+++ b/src/com/android/mms/ui/ConversationList.java
@@ -334,10 +334,23 @@
 
         if (position == 0) {
             createNewMessage();
-        } else if (v instanceof ConversationListItem) {
-            ConversationListItem headerView = (ConversationListItem) v;
-            ConversationListItemData ch = headerView.getConversationHeader();
-            openThread(ch.getThreadId());
+        } else {
+            // Note: don't read the thread id data from the ConversationListItem view passed in.
+            // It's unreliable to read the cached data stored in the view because the ListItem
+            // can be recycled, and the same view could be assigned to a different position
+            // if you click the list item fast enough. Instead, get the cursor at the position
+            // clicked and load the data from the cursor.
+            // (ConversationListAdapter extends CursorAdapter, so getItemAtPosition() should
+            // return the cursor object, which is moved to the position passed in)
+            Cursor cursor  = (Cursor) getListView().getItemAtPosition(position);
+            Conversation conv = Conversation.from(this, cursor);
+            long tid = conv.getThreadId();
+
+            if (LogTag.VERBOSE) {
+                Log.d(TAG, "onListItemClick: pos=" + position + ", view=" + v + ", tid=" + tid);
+            }
+
+            openThread(tid);
         }
     }