• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Move items up or down in List?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic