Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...