Creating the choice list

To use a choice list in your application, create an instance of the class CAknChoiceList .

Use the CAknChoiceList::NewL parameters to set the style of the choice list.

If you give no parameters, the defaults will be used. With the default parameters, a choice list with current selection is constructed.

To construct a choice list without a current selection, use the flag CAknChoiceList::EaknChoiceListWithoutCurrentSelection and an instance of CaknButton in the constructor. This button will be then used to open the choice list. The ownership of the button is transferred to the choice list.

The following sample code illustrates creating a default choice list.

      const TInt KArrayGranularity ( 1 );
 
   // Create array of choice list items        
    CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat ( KArrayGranularity );
    CleanupStack::PushL( array );
    
    _LIT( KListItem, "Item %d" );

    for ( TInt k = 0; k < 5; k++ )
        {
        TBuf<32> buf;
        buf.Format( KListItem, k );
        array->AppendL( buf );
        }
 
    // Create choice list with array
    iChoiceList = CAknChoiceList::NewL( this, array );
    
    CleanupStack::Pop( array );
    
    iChoiceList->SetObserver( this );
     

The following sample code illustrates creating a button choice list with items from resources:

      _LIT( KButtonTxt, "Choice list" );
    _LIT( KButtonHelpTxt, "Button help text" );

    // Create a button for the choice list
    CAknButton* button = CAknButton::NewLC( NULL,
                                            NULL,
                                            NULL,
                                            NULL,
                                            KButtonTxt,
                                            KButtonHelpTxt,
                                            KAknButtonSizeFitText,
                                            0 );
 
    // Create empty Choice list
    iChoiceList = CAknChoiceList::NewL( this, NULL, 
        CAknChoiceList::EAknChoiceListWithoutCurrentSelection, button );
    CleanupStack::Pop( button );
 
    // Add items from resource
    iChoiceList->SetItemsL( R_CHOICELISTEX_ITEM_ARRAY );
    iArraySize = ArraySizeL( R_CHOICELISTEX_ITEM_ARRAY );
    iSelection = 0;
    
    iChoiceList->SetObserver( this );