Namespaces
Variants
Actions
(Difference between revisions)

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

Jump to: navigation, search
m (Hamishwillee - Bot change of template (Template:KnowledgeBase) - now using Template:ArticleMetaData)
m (Hamishwillee - Adding missing translation link)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{KBTS}}
+
{{Archived|timestamp=20120314051316|user=roy.debjit| }}
__NOTOC__
+
[[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]][[Category:S60 2nd Edition (initial release)]][[Category:S60 3rd Edition (initial release)]][[Category:S60 3rd Edition FP1]]
__NOEDITSECTION__
+
{{ArticleMetaData <!-- v1.2 -->
 
+
[[Category:Technical Solution]]
+
 
+
{{ArticleMetaData
+
|id=TSS000647
+
|platform=S60 1st Edition<br>S60 2nd Edition and FP1, FP2, FP3<br>S60 3rd Edition and FP1
+
|devices=
+
|category=Symbian C<nowiki>++</nowiki>
+
|subcategory=UI, UI components
+
|creationdate=May 10, 2007
+
|keywords=
+
 
+
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= S60 1st Edition<br>S60 2nd Edition and FP1, FP2, FP3<br>S60 3rd Edition and FP1
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices.) -->
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|author=[[User:Technical writer 2]]
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20070510
 +
|author= [[User:Technical writer 2]]
 +
<!-- The following are not in current metadata -->
 +
|id= TSS000647
 
}}
 
}}
  
Line 27: Line 30:
  
 
== Description ==
 
== Description ==
Below is a code snippet demonstrating how to apply actions on a list box item selected by the user.<br>The code to create a simple list box can be obtained from the link below:<br>[[How to create a simple listbox<br>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.
+
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 ==
 
== Solution ==
&nbsp;&nbsp;&nbsp;&nbsp;TKeyResponse CMyExampleAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(aType != EEventKey)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EKeyWasNotConsumed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(aKeyEvent.iCode)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EKeyUpArrow:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EKeyDownArrow:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Forward up and down key press events to the list box<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return iListBox-<nowiki>></nowiki>OfferKeyEventL( aKeyEvent, aType );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case EKeyOK: // display an information note when item is selected<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_LIT(KFormatMessage, "Selected item: %d");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TInt idx = iListBox-<nowiki>></nowiki>CurrentItemIndex();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TBuf<nowiki><</nowiki>32<nowiki>></nowiki> message;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message.Format(KFormatMessage, idx);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CAknInformationNote* Note = new (ELeave) CAknInformationNote;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Note-<nowiki>></nowiki>ExecuteLD(message);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EKeyWasConsumed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EKeyWasNotConsumed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>Also make sure to add this line<br>&nbsp;&nbsp;&nbsp;&nbsp;AddToStackL( iAppView ); <br>in AppUi<nowiki>’</nowiki>s ConstructL() to add the view/container to the control stack and receive OfferKeyEventL() calls.
+
<code cpp>
 +
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;
 +
        }
 +
</code>
  
[[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]] [[Category:S60 2nd Edition]] [[Category:S60 3rd Edition]] [[Category:S60 3rd Edition, Feature Pack 1]]
+
Also make sure to add this line
 +
<code cpp>AddToStackL( iAppView );</code>
 +
in AppUi's {{Icode|ConstructL()}} to add the view/container to the control stack and receive {{Icode|OfferKeyEventL()}} calls.
 +
<!-- Translation --> [[zh-hans:如何在列表框项中响应动作]]

Latest revision as of 08:34, 18 September 2012

Archived.png
Archived: 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

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 08:34.
150 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