Saravanan
Saravanan

Reputation: 11592

J2ME Commends Order

I have mixed some different types of command like OK,CANCEL,BACK,EXIT,SCREEN in my application.

For Example,

exit = new Command("Exit", Command.EXIT, 5);
_123=new Command("123",Command.BACK,4);
ABC=new Command("ABC",Command.CANCEL,3);
sample1=new Command("Sample1",Command.SCREEN,1);
sample2=new Command("Sample2",Command.OK,2);

The Order i need is :Sample1,Sample2,ABC,Exit. But it Display like this Sample1,Sample2,Exit,ABC are right side and 123 is placed in left side button.

Here, I also have one problem while adding one more command(Edit_Cell) using like below.... and also i need to display in the first place before Sample1.But it displayed in End of all the commands on right hand side.

I have added this new Command(Edit_Cell) in another src file constructor and call that constructor in below of my above code(adding commands).

Edit_Cell is type of SCREEN and PRIORITIES IS 1 on the other source file.

My Final Order i need is : Edit_Cell,Sample1,Sample2,ABC,Exit, on right hand side and _123 on left hand side.

Upvotes: 4

Views: 1333

Answers (2)

mdelolmo
mdelolmo

Reputation: 6447

I reply to your comment here, it's less messy... Maybe it's displaying the commands in the same order they were added (not using priorities). I would delete all commands when Edit_Cell is added and add them all again, after Edit_Cell is added. If you can only modify your form's code, then you can override the addCommand method to ensure when Edit_Cell is added all previous commands are removed and added again later.

Something like this:

@Override
    public void addCommand(Command cmd) {
        if (cmd.getLabel().equals("Edit_Cell")){
           removeCommand(sample1); // with all the previously added commands
        }
        super.addCommand(cmd);
        if (cmd.getLabel().equals("Edit_Cell")){
          addCommand(sample1); // again with all your previously added commands
        }
    }

It's not very elegant, but well, you can always make it more classy, as long as it works....

Upvotes: 0

mdelolmo
mdelolmo

Reputation: 6447

First of all, and without offense, I think you should elaborate a bit more your written compositions, it took me a while to understand the issue.

Still, the way you claim commands makes sense according to this (Nokia's wiki forum):

The Command mapping to softkeys follow following rules:

Right softkey: There can be only one "negative" Command (STOP, CANCEL, BACK, EXIT in this priority order) mapped to Right softkey, and the Command mapped there is directly invoked by softkey press.

Left softkey: Mutiple commands can be mapped under Left softkey in which case there is "Options" label in Left softkey and selection of it will open a menu of commands. If there's however only a single "positive" Command (OK, ITEM, SCREEN or HELP) under left softkey it will be presented directly on Left softkey. (Note: Some LCDUI components have their own operations that will be also visible under left softkey thus forcing Options menu.) If there's more than one negative Command this will force Options menu on Left softkey and the commands will be presented in the order define below.

Middle softkey: In Series 40 only a single context sensitive Command (OK, ITEM) is mapped to Middle softkey. In S60 multiple context sensitive Commands (OK, ITEM) can be mapped to Middle Softkey. If there's only single Command it will be shown directly in softkey, otherwise commands are visible in context sensitive menu opened from middle softkey. Normally the same commands mapped to Middle softkey are also available in Left softkey (directly or via Options menu). Note: Some UI components override this rule and place component specific operation directly to Middle softkey. For example, POPUP ChoiceGroup has "Open" operation in Middle softkey.

Obviously this depends a lot on the platform, but it seems your midlet is assuming _123 as the negative Command, and all others are placed on the other soft key.

I would try to change the types and set the priorities as you wish... something like this

exit = new Command("Exit", Command.EXIT, 5);
_123=new Command("123",Command.BACK,0);
ABC=new Command("ABC",Command.SCREEN,3);
sample1=new Command("Sample1",Command.SCREEN,1);
sample2=new Command("Sample2",Command.OK,2);

And you can set the priority of Edit_Cell to 0 and its type to SCREEN. And just to add: ITEM commands are usually placed before.

I hope this helps. Regards.

Upvotes: 5

Related Questions