# Bananas-Plus: BMovableList help



## perrce (Feb 8, 2007)

s2kdave: I need a little help with using BMovableList in Bananas-Plus. Right now, I subclass BMovableList and have a createRow() that include this line:


```
text.setValue( String.valueOf(index + 1) + ". " + ((Playable)this.get(index)).getTrackName() + " - " + ((Playable)this.get(index)).getArtistName());
```
The important thing is that the items in the list are numbered. When I reorder the list using the mover button, the item that is being moved has it's label updated (presumably because createRow() is called when add() is called in BMoveableList.move() ), but the label on the item being bumped does not. So if I started with a list that looks like this:

1. this
2. is
3. a
4. sample
5. list

and I moved item 3 up one spot, I would end up with a list that looks like this:

1. this
2. a
2. is
4. sample
5. list

Is there any easy way to force an update of the label on the list item that's been bumped? I don't really want to reimplement the entire move() method to force an update. Any suggestions?


----------



## s2kdave (Jan 28, 2005)

you will also have the same problem when doing a channel down to jump a page at a time. You will have to reload all the entries between the old and new location. You can do this with the current version by responding to the MoveEvent that gets fired after a move. There is a side effect with updating the UI by adding/removing in that it pretty much renders the setPainting toggle useless. So I've added a couple new methods that will help and updated the sample to include the index in the text.

Because changing the rendering of the value during a move isn't common and it is somewhat expensive to rebuild the views when you don't need to, I didn't make it the default behavior. I added a reloadRow(index) and reloadRows(start, end) method to force a reload of the view, but to disable the painting so that you don't see the UI update while the different methods are being called. It's kind of a hack I made to work around the problems with BList, but it's mostly hidden. I also added a protected moveValue() method just in case someone might find it useful to override the actual moving of the value from one position to another.

I made a new version of the jar.


```
public boolean handleEvent(HmeEvent event) {
        if (event instanceof MoveEvent) {
            MoveEvent moveEvent = (MoveEvent)event;
            int start = moveEvent.getOldIndex();
            int end = moveEvent.getNewIndex();
            if (start > end) {
                start = moveEvent.getNewIndex();
                end = moveEvent.getOldIndex();
            }
            list.reloadRows(start, end);
            return true;
        }
        return super.handleEvent(event);
    }
```


----------



## s2kdave (Jan 28, 2005)

I also added the latest javadoc to the project.
http://bananas-plus.googlecode.com/svn/trunk/javadoc/index.html


----------



## perrce (Feb 8, 2007)

Thanks for the help. I'll play with it this evening.


----------



## perrce (Feb 8, 2007)

Thanks for the update. It works great.


----------

