Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Move items up or down in List?

 
Gary Bryan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!