How does the Form.getCommand(int index) work?

Viewed 38

I have a current Form(previousForm) with a previousForm as a parameter. My goal is to get a specific Command of this previousForm (reload the data of the previousForm and then do showBack()) from the current Form. The problem is that I can't reach this specific Command from my current form. While doing research on this problem, I found getCommand(int index) method, and I would like to clarify how it works.

The documentation of Form says that it

Returns the command occupying the given index

How can I find the index of my Command? Or how can I set it? I see there is a Command's constructor Command(String command, int id) , however this id is not the index.

1 Answers

I suggest going at this in a different route. Just do something like this:

public class MyForm extends Form {
    public void reload() {
       //...
    }
}

Then in your back command just downcast to MyForm and invoke reload. Make sure all forms are of type MyForm.

getCommand() is meant for use with getCommandCount() so you can loop over all commands and extract them from the parent Form.

Related