Namespaces
Variants
Actions
Revision as of 09:33, 15 June 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Archived:Adding items to listbox dynamically

Jump to: navigation, search
Archived.png
Archived: 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

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:

213 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved