You Are Here:

Community: Wiki

This page was last modified on 9 May 2009, at 17:10.

Adding items to listbox dynamically

From Forum Nokia Wiki


How to add an item to a CAknDoubleLargeStyleListBox

This article describes the process of adding an item 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 );
}

. .

and Finally add the created icon to the list box

CArrayPtr<CGulIcon>* iconList=iListBox->ItemDrawer()->ColumnData()->IconArray();
iconList->InsertL(0,yourClass->GetIconFromResource());
 
and 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:

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia