bug #3319036: fix one of the (severe) SMS bugs where the wrong conversation is opened.

- the code in ConversationList.onListItemClicked() was extracting the conversation data
from the ConversationListItem view passed in. However, ListItem views can be recycled
when rebound, so the view we got could now be reassigned to a different list position
and contain different data.

Intead of depend on ConversationListItem to store the conversation data, always load
the cursor at the position clicked, and get the conversation data from the cursor.

Merge from gingerbread

Conflicts:

	src/com/android/mms/ui/ConversationList.java

Change-Id: I276a2ffc48fb51a99c87584d7604f188aec1cb98
diff --git a/src/com/android/mms/ui/ConversationList.java b/src/com/android/mms/ui/ConversationList.java
index 2707fc8..2422b4a 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 (LOCAL_LOGV) {
+                Log.v(TAG, "onListItemClick: pos=" + position + ", view=" + v + ", tid=" + tid);
+            }
+
+            openThread(tid);
         }
     }