Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Move items up or down in List?  RSS feed

Gary Bryan
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); - 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); + 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!