Symbian
Symbian OS Library

FAQ-0730 Why do my Lists (Choices) not behave as expected when my application is ported to the Nokia 9210?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: AWT
Created: 08/21/2001 Modified: 09/03/2001
Number: FAQ-0730
Platform: Symbian OS v6.0

Question:
Why do my Lists (Choices) not behave as expected when my application is ported to the Nokia 9210 ? For instance when I try to navigate the List with the four-way keypad the first item highlighted gets selected, whether I want it or not.

Answer:
User interaction with the Nokia 9210 is primarily via the keyboard or the soft keys of the Command Button Array (CBA), unlike the more familar mouse- (or pointer-) driven style that users are more familar with from the desktop world. This requires a change in style on the part of the developer when developing for (or porting to) the Nokia 9210. We shall illustrate this with an example. Consider the following code

    ...
    public class ListDialog extends Dialog implements ItemListener {
    ...
    private List drinkList;

    public ListDialog(Frame parent){
    super(parent);
    drinkList = new List(6);
    drinkList.add("Vodka");
    drinkList.add("Gin");
    ...
    drinkList.addItemListener(this);
    add(drinkList);
    ...
    }


    public void itemStateChanged(ItemEvent ie){
    String drink = drinkList.getSelectedItem();
    //do something with selected drink
    ...
    }
    ...
    }


    This would be the standard way to choose an item from a List on a mouse-driven desktop system. However, it proves unsatisfactory on the 9210 since, to navigate the List, it is necessary to use the four-way keypad (assuming the virtual cursor has not been enabled). However, the instant the key pad is pressed an ItemEvent is generated and the itemStateChanged(...) method triggered with the selected item being the one that is currently highlighted, which is not necessarily the item that is in fact desired. It is not therefore possible directly to select the desired item.

    The recommended way to choose an item from a List when developing for the Nokia 9210 would be to use the CBA to select the item as follows

    ....
    public class ListDialog extends Dialog implements CBAListener {
    ...
    private List drinkList;
    private EikCommandButtonGroup cbg;

    public ListDialog(Frame parent, EikCommandButtonGroup cbg){
    super(parent);
    this.cbg = cbg;
    drinkList = new List(6);
    drinkList.add("Vodka");
    drinkList.add("Gin");
    ...
    add(drinkList);
    ...
    cbg.addCBAListener(this);
    cbg.setEnabled(EikCommandButtonGroup.BUTTON1, true); cbg.setText(EikCommandButtonGroup.BUTTON1, "Select");
      ...
      }


      public void cbaActionPerformed(CBAEvent ae){

      String drink = drinkList.getSelectedItem();
      //do something with selected drink
      ...
      }

      ...
      }


      In this example the first button of the CBA is enabled for selection of the item and a CBAListener (rather than an ItemListener) added to the Dialog. The List can now be navigated correctly using the four-way keypad and when the required item is highlighted the user presses the "Select" button of the CBA. This triggers the cbaActionPerformed(...) method and the correct item is selected via the getSelectedItem() method of the List class.