Custom Avkon pop-up list
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
Source file: File:TestSingleTap.zip
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);
}


(no comments yet)