×
Namespaces

Variants
Actions

Archived:Adding items to listbox dynamically

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Compatibility
Platform(s): S60 3rd Edition FP 1
S60 3rd Edition FP1
Article
Keywords: CAknDoubleLargeStyleListBox
Created: vdharankar (27 Apr 2009)
Last edited: hamishwillee (15 Jun 2012)


How to add an item to a CAknDoubleLargeStyleListBox

This article describes the process of adding an item to an Avkon listbox at runtime.

Two steps are necessary:

  1. Create text item and add it to the text item array
  2. Create the icon and add it to the icons array

Both the items should be assigned to the same index remember else you may landup with panic AVKON 0

  1. Create text item and add it to the text item array
    _LIT16(M,"0\tHello\tHi");
    TBuf16<100> b;
    CTextListBoxModel* model =iListBox->Model();
    CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );
    itemArray->InsertL(0,M);
  2. Create Icon and add it to the icons array - this is bit tricky
    CGulIcon* YourClass::GetIconFromResource()
    {
    CGulIcon* icon;
    icon = LoadAndScaleIconL(
    KYourResourceFile, EMbmIconId, -1,
    NULL, EAspectRatioPreserved );
    return icon;
     
    }
     
    CGulIcon* YourClass::LoadAndScaleIconL(
    const TDesC& aFileName,
    TInt aBitmapId,
    TInt aMaskId,
    TSize* aSize,
    TScaleMode aScaleMode )
    {
    CFbsBitmap* bitmap;
    CFbsBitmap* mask;
    AknIconUtils::CreateIconL( bitmap, mask, aFileName, aBitmapId, aMaskId );
     
    TSize size;
    if ( aSize == NULL )
    {
    // Use size from the image header. In case of SVG,
    // we preserve the image data for a while longer, since ordinarily
    // it is disposed at the first GetContentDimensions() or SetSize() call.
    AknIconUtils::PreserveIconData( bitmap );
    AknIconUtils::GetContentDimensions( bitmap, size );
    }
    else
    {
    size = *aSize;
    }
     
    AknIconUtils::SetSize( bitmap, size, aScaleMode );
    AknIconUtils::SetSize( mask, size, aScaleMode );
     
    if ( aSize == NULL )
    {
    AknIconUtils::DestroyIconData( bitmap );
    }
     
    return CGulIcon::NewL( bitmap, mask );
    }
  3. Add the created icon to the list box.
    CArrayPtr<CGulIcon>* iconList=iListBox->ItemDrawer()->ColumnData()->IconArray();
    iconList->InsertL(0,yourClass->GetIconFromResource());
  4. Finally, you need to notify the listbox that new items have been added
    iListBox->HandleItemAdditionL();

Placing this code in appropriate class is your responsibility :) You may need to slightly change this code based on the location of your listbox

Related Links:

This page was last modified on 15 June 2012, at 09:33.
60 page views in the last 30 days.
×