Weird bug in TouchListView

If you’re trying to create a drag-and-drop ListView using the TouchListView (aka cwac-touchlist) library (which essentially refactors the code used by Google in the playlist tab of the Music app), you may encounter an undocumented bug: If two or more items have the same content, say, the same String value, and you attempt to drag and drop them together, the list items will randomly reshuffle and not let that happen. I drove myself crazy trying to find the cause of this bug, but I couldn’t find anything (It’s not often that listViews have the same content repeated in multiple rows, I suppose).

Anyway, to work around the bug, I came up with this silly hack:

StringBuilder builder = new StringBuilder();
builder.append(word);
if(arrayList.contains(word))
{
for(int i=0;i<arrayList.size();i++)
builder.append(” “);
}
adapter.add(builder.toString());
adapter.notifyDataSetChanged();

word is a String being added to the ListView. To avoid multiple rows having the same value, I’ve had to resort to padding the word with spaces!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s