×
Namespaces

Variants
Actions

Pop up list example

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: symbianyucca (04 Apr 2007)
Last edited: ltomuta (06 May 2012)



The SelectSomethingL() method illustrates how to use Popup lists for displaying data or for showing a selection to the user. In this example five constant strings are added to the selection but you could also make this part dynamic.

With this example the Popup list is constructed as CAknSinglePopupMenuStyleListBox, but you could also use following types of Popuplists:

  • CAknSingleHeadingPopupMenuStyleListBox
  • CAknSingle2GraphicPopupMenuStyleListBox
  • CAknSingleGraphicPopupMenuStyleListBox
  • CAknSingleGraphicHeadingPopupMenuStyleListBox
  • CAknSingleGraphicBtPopupMenuStyleListBox
  • CAknDoubleGraphicPopupMenuStyleListBox
  • CAknDouble2PopupMenuStyleListBox
  • CAknDoublePopupMenuStyleListBox
  • CAknDoubleLargeGraphicPopupMenuStyleListBox

Note that the format for the item text string depends on the Popup list type. If you change the Popup list type you also need to modify the item text string format accordingly.

Includes:
#include <aknlists.h>
#include <aknpopup.h>
#include <BADESCA.H>
 
Link Against:
avkon.lib
eikctl.lib
eikcoctl.lib
bafl.lib


_LIT(KtxPopUpTitle			,"Select item");
 
_LIT(KtxPopUpItem1 ,"Item 1");
_LIT(KtxPopUpItem2 ,"Item 2");
_LIT(KtxPopUpItem3 ,"Item 3");
_LIT(KtxPopUpItem4 ,"Item 4");
_LIT(KtxPopUpItem5 ,"Item 5");
 
void SelectSomethingL(TDes& aSelected)
{
CAknSinglePopupMenuStyleListBox* list =
new(ELeave)CAknSinglePopupMenuStyleListBox;
CleanupStack::PushL(list);
 
CAknPopupList* popupList = CAknPopupList::NewL(list,
R_AVKON_SOFTKEYS_OK_BACK, AknPopupLayouts::EMenuWindow);
CleanupStack::PushL(popupList);
 
list->ConstructL(popupList, 0);
list->CreateScrollBarFrameL(ETrue);
list->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,
CEikScrollBarFrame::EAuto);
 
CDesCArrayFlat* ItemArray = new(ELeave)CDesCArrayFlat(5);
CleanupStack::PushL(ItemArray);
 
// add the item adding in here..
ItemArray->AppendL(KtxPopUpItem1);
ItemArray->AppendL(KtxPopUpItem2);
ItemArray->AppendL(KtxPopUpItem3);
ItemArray->AppendL(KtxPopUpItem4);
ItemArray->AppendL(KtxPopUpItem5);
 
CleanupStack::Pop(); //ItemArray
list->Model()->SetItemTextArray(ItemArray);
list->Model()->SetOwnershipType(ELbmOwnsItemArray);
 
popupList->SetTitleL(KtxPopUpTitle);
 
// Show popup list and then show return value.
TInt popupOk = popupList->ExecuteLD();
if (popupOk)
{
TInt Sel = list->CurrentItemIndex();
if (Sel >= 0 && Sel < ItemArray->MdcaCount())
{
aSelected.Copy(ItemArray->MdcaPoint(Sel));
}
}
 
CleanupStack::Pop(); // popuplist
CleanupStack::PopAndDestroy(1); // list
}


If you want to further customize your pop-up list's behavior, you can subclass CAknPopupList and provide your own implementation for HandleListBoxEventL() and/or OfferKeyEventL(). See Custom Avkon pup-up list.

This page was last modified on 6 May 2012, at 15:49.
41 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×