Background: I'm trying to implement a messenging system in my app, and I'm writing a custom CursorAdapter
to display the messages in a ListView
in the chat window. I want to use a different row layout for incoming and outgoing messages (information that is saved in the SQLite row in the cursor). Each row has the same elements in it with the same IDs, but they are arranged differently.
The Problem: Currently, I have overridden newView()
and bindView()
. When the ListView
is first populated, it creates all of the View
s perfectly, checking each row to see if it's either incoming or outgoing, and inflating the proper XML file. However, when I scroll or a new message is added to the window, the adapter recycles View
s for the wrong rows. I would override getView()
, but it is not passed the Cursor
as a parameter, so I have no way of knowing whether the row should be incoming or outgoing.
I'm not looking for code, but rather, some suggestion for an elegant implementation. Thanks in advance!