I am trying to move items in a List (on 1.0) up or down. I thought of the code below, but it doesn't work.
else if (t == up) {
String goingDownItem = topList.getItem(topList.getSelectedIndex() - 1);
String goingUpItem = topList.getItem(topList.getSelectedIndex());
topList.replaceItem(goingDownItem, topList.getSelectedIndex());
topList.replaceItem(goingUpItem, topList.getSelectedIndex() - 1);
topList.select(topList.getSelectedIndex() - 1);
return true;
}
else if (t == down) {
String goingDownItem = topList.getItem(topList.getSelectedIndex());
String goingUpItem = topList.getItem(topList.getSelectedIndex() + 1);
topList.replaceItem(goingUpItem, topList.getSelectedIndex());
topList.replaceItem(goingDownItem, topList.getSelectedIndex() + 1);
topList.select(topList.getSelectedIndex() + 1);
return true;
}
where t is the event's target.
The idea is that the text of the selected item, and the text of the item item above it (for moving up) or below it (for moving down) are put into Strings, then they are replaced with each other. I get a lot of strange effects with items not moving, staying the same, moving to the top of the list, etc.