DragSortAdapter icon indicating copy to clipboard operation
DragSortAdapter copied to clipboard

I have a similar issue with #11,"use the DragSortAdapter with List<String>"

Open guobuping opened this issue 9 years ago • 1 comments

I change Integer to String with hashCode() and it'll crash if I drag the item.It's like #11 .Could you show me a right example how to use it ? Thank you very much!

guobuping avatar Jun 07 '15 13:06 guobuping

Hey, I think i have a clean solution for this problem. For storing your objects use a HashMap<Integer, <YourObject> objects; For storing the keys use a ListView<Integer> keys;

Get Object from position:

YourObject yourObject = yourObjects.get(keys.get(position));

Add object:

int key = phases.hashCode();
keys.add(key);
phases.put(key, phase);
notifyDataSetChanged();

Remove object:

int key = keys.get(phase.hashCode());
keys.remove(key);
phases.remove(key);
otifyDataSetChanged();

Override methods:

@Override
    public int getItemCount() {
        return keys.size();
    }

    @Override
    public long getItemId(int position) {
        return keys.get(position);
    }

    @Override
    public int getPositionForId(long id) {
        return keys.indexOf((int)id);
    }

    @Override
    public boolean move(int fromPosition, int toPosition) {
        keys.add(toPosition, keys.remove(fromPosition));
        return false;
    }

Kieninger avatar Jul 26 '15 09:07 Kieninger