Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Custom Avkon pop-up list

From Wiki
Jump to: navigation, search

This article will show how to subclass CAknPopupList in order to customize its behavior. You can for example make it return the selected item after only one selection tap instead of two.

Article Metadata
Code ExampleArticle
Keywords: CAknPopupList
Created: ltomuta (06 May 2012)
Last edited: hamishwillee (30 May 2013)


The solution is rather simple: subclass CAknPopupList and implement the handling of the tap and key events:

class CCustomPopupList : public CAknPopupList
// Constructors and destructor
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
void FocusChanged(TDrawNow aDrawNow);
void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
CAknSinglePopupMenuStyleListBox* iList;
TBool iIsFocused;
TInt& iCurrentItem;
void CCustomPopupList::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
if ( aEventType == EEventEnterKeyPressed || aEventType == EEventItemSingleClicked || aEventType == EEventItemClicked )
AttemptExitL( ETrue );
CAknPopupList::HandleListBoxEventL( aListBox, aEventType );
TKeyResponse CCustomPopupList::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
TKeyResponse response = EKeyWasNotConsumed;
if ( aType == EEventKey && aKeyEvent.iCode == EKeyEscape )
AttemptExitL( EFalse );
response = EKeyWasConsumed;
response = iList->OfferKeyEventL(aKeyEvent, aType);
if ( aType == EEventKey && !iIsFocused )
switch ( aKeyEvent.iCode )
case EKeyUpArrow:
case EKeyDownArrow:
case EKeyDevice3:
case EKeyEnter:
iIsFocused = ETrue;
iList->SetCurrentItemIndexAndDraw( iCurrentItem );
return response;

For a full example see \src\CustomPopupList.cpp and \inc\CustomPopupList.h in the attached project.

To use the new class:

TInt select=1;
CCustomPopupList* list = CCustomPopupList::NewL(select);
TInt popupOk = list->ExecuteLD();
if (popupOk)
// _LIT(KMessage, "Selected: %d");
// TBuf<100> message;
// message.Format(KMessage, select);
// CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
// informationNote->ExecuteLD(message);
This page was last modified on 30 May 2013, at 04:32.
43 page views in the last 30 days.