Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...