views:

32

answers:

2

I'm having some trouble setting the FieldChangeListener of a new button I am creating after an action is performed. I have a list of ButtonFields and when I create a new VoiceNote a new ButtonField linking to that VoiceNote is added.

I create a new voice note to be edited in another screen and when that screen is closed the note is added to my database and the new button is added to the list. The button is added correctly but when I click on it, it does nothing.

The code of the MenuItem that invokes this is as follows:

private final class NewNote extends MenuItem
{
    Vector _voiceNotes;
    ListStyleButtonField _nuevoBoton;
    public NewNote(Vector voiceNotes)
    {
        super("New Voice Note",0,0);
        _voiceNotes = voiceNotes;
    }

    public void run() {
        VoiceNote newNote = new VoiceNote("", "", null);
        UiApplication.getUiApplication().pushModalScreen(new RecordScreen(_managerBD, newNote));
        if(newNote.get_id() != -1)
        {
            _voiceNotes.addElement(newNote);
            _nuevoBoton = new ListStyleButtonField(newNote.get_nombre(), 0);
            add(_nuevoBoton);

            newNote.set_noteIndex(_nuevoBoton.getIndex());
            UiApplication.getUiApplication().invokeAndWait(new Runnable() {
                public void run() {
                    _nuevoBoton.setChangeListener(UiApplication.getUiApplication().getActiveScreen().getChangeListener());
                }
            });
            UiApplication.getUiApplication().relayout();
        }
    }
}
A: 

You are setting the change listener to be the same as whatever change listener is set for the active screen. Have you set a change listener for the active screen?

Michael Donohue
No i haven't set it. But, when i set my buttons on load i always do button.setChangeListener(this) i'm asuming "this" is the change listener for the screen, what would be the equivalent in this case?
8vius
Solved the problem changed where i set the listener to _nuevoBoton.setChangeLister((SavedNotesScreen)UiApplication.getUiApplication().getActiveScreen()) since my SavedNotesScreen class implements change listener that's all that was needed
8vius
A: 

Anyone have any clue as to what my problem is? Still haven't found a way to solve it

8vius