Namespaces
Variants
Actions

Custom Avkon pop-up list

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 Example
Article
Keywords: CAknPopupList
Created: ltomuta (06 May 2012)
Last edited: hamishwillee (13 Jul 2012)

Summary

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

class CCustomPopupList : public CAknPopupList
{
public:
// Constructors and destructor
...
 
private:
 
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
 
void FocusChanged(TDrawNow aDrawNow);
 
void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
 
private:
CAknSinglePopupMenuStyleListBox* iList;
TBool iIsFocused;
TInt& iCurrentItem;
};
void CCustomPopupList::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
{
if ( aEventType == EEventEnterKeyPressed || aEventType == EEventItemSingleClicked || aEventType == EEventItemClicked )
{
AttemptExitL( ETrue );
}
else
{
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;
}
else
{
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 );
break;
default:
break;
}
}
 
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 13 July 2012, at 08:55.
200 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