×
Namespaces

Variants
Actions

Archived:Applying actions on list box items using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Compatibility
Platform(s): S60 1st Edition
S60 2nd Edition and FP1, FP2, FP3
S60 3rd Edition and FP1
S60 3rd Edition FP1
S60 3rd Edition (initial release)
S60 2nd Edition (initial release)
S60 1st Edition
Article
Created: User:Technical writer 2 (10 May 2007)
Last edited: hamishwillee (18 Sep 2012)

Overview

Applying actions on list box items

Description

Below is a code snippet demonstrating how to apply actions on a list box item selected by the user.

The code to create a simple list box can be obtained from the link: How to create a simple listbox in Symbian C++. It is possible to apply any actions (e.g., displaying a popup or a dialog) by catching key events for a list box that currently has keyboard focus. This is done in the OfferKeyEventL() function of the container class that owns the list box.

Solution

TKeyResponse CMyExampleAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
switch(aKeyEvent.iCode)
{
case EKeyUpArrow:
case EKeyDownArrow:
{
// Forward up and down key press events to the list box
return iListBox->OfferKeyEventL( aKeyEvent, aType );
}
case EKeyOK: // display an information note when item is selected
{
_LIT(KFormatMessage, "Selected item: %d");
TInt idx = iListBox->CurrentItemIndex();
TBuf<32> message;
message.Format(KFormatMessage, idx);
CAknInformationNote* Note = new (ELeave) CAknInformationNote;
Note->ExecuteLD(message);
return EKeyWasConsumed;
}
default:
break;
}
return EKeyWasNotConsumed;
}

Also make sure to add this line

AddToStackL( iAppView );

in AppUi's ConstructL() to add the view/container to the control stack and receive OfferKeyEventL() calls.

This page was last modified on 18 September 2012, at 05:34.
80 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.

×