-
Notifications
You must be signed in to change notification settings - Fork 289
Library breaks when there are items with similar text #25
Comments
This happens because in case of duplicating Strings in input list, after all invocations of org.askerov.dynamicgrid.AbstractDynamicGridAdapter#addStableId method, mIdMap will contain only 1 entry (with "Abbaye de Belloc" key from example above). A simple workaround is to pass not a List of Strings to the Adapter, but a list of some String wrappers, like
|
We have also noticed an issue with disappearing items in our grid.. it happens with more complex items too. I haven't had the time to debug the issue yet. It happens sometimes and not others.. |
The reason is implementation of stable id in AbstractDynamicGridAdapter. Ids are stores in HashMap<Object, Integer> and it is not good for equals objects. So you should not have equals objects in adapter, or write your own implementation of getItemId() method. |
I have an implementation of getItemId that returns the DB id of the item in the grid. I will investigate further. |
I think I have a clue here... sometime the reorderElements() is called repeatedly while the drag is in progress, and when this happens the grid gets very messed up.. I am still looking for the reason for this. |
@dbachelder use StringHolders similar to what I have provided above, as array elements. The reason, as @askerov has stated, is that array items are stored in hash map as keys, so equal strings override each other. Using StringHolder objects, which are not equal even with equal wrapped strings, solves the problem. Then in your adapter you extract the string out of StringHolder and use that in your view. |
I don't have strings I'm using unique IDs via an implementation of getstableid that returns database IDs. But I am seeing the reorderelemebts method called rapidly during a drag with the same position parameters passed in every call. I'm am trying to debug between meetings |
I figured this out. Totally my bug. sorry for the noise. |
In provided example, replace sCheeseString with
then try to drag. The items become not draggable and disappear randomly.
The text was updated successfully, but these errors were encountered: