Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Library breaks when there are items with similar text #25

Closed
denisk20 opened this issue Jul 20, 2014 · 8 comments
Closed

Library breaks when there are items with similar text #25

denisk20 opened this issue Jul 20, 2014 · 8 comments

Comments

@denisk20
Copy link
Contributor

In provided example, replace sCheeseString with

public static final String[] sCheeseStrings = {
            "Abbaye de Belloc", "Abbaye de Belloc", "Abbaye de Belloc"
    };

then try to drag. The items become not draggable and disappear randomly.

@denisk20
Copy link
Contributor Author

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

private static class StringHolder {
    String s;

    StringHolder(String s) {
        this.s = s;
    }
}

@dbachelder
Copy link

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..

@askerov
Copy link
Owner

askerov commented Jul 21, 2014

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.

@dbachelder
Copy link

I have an implementation of getItemId that returns the DB id of the item in the grid. I will investigate further.

@dbachelder
Copy link

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.

@denisk20
Copy link
Contributor Author

@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.

@dbachelder
Copy link

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

@dbachelder
Copy link

I figured this out. Totally my bug. sorry for the noise.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants