Archived:Applying actions on list box items using Symbian C++
m (Protected "TSS000647 - Applying actions on list box items": KB [edit=sysop:move=sysop]) |
extkbeditor1
(Talk | contribs) m |
||
| Line 5: | Line 5: | ||
[[Category:Technical Solution]] | [[Category:Technical Solution]] | ||
| − | {| | + | {{KnowledgeBase |
| − | | | + | |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= | ||
| + | }} | ||
| − | + | == 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.<br>The code to create a simple list box can be obtained from the link below:<br>http://wiki.forum.nokia.com/index.php/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. | |
| − | + | ||
| − | + | == Solution == | |
| − | + | TKeyResponse CMyExampleAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)<br> <nowiki>{</nowiki><br> if(aType != EEventKey)<br> <nowiki>{</nowiki><br> return EKeyWasNotConsumed;<br> <nowiki>}</nowiki><br> switch(aKeyEvent.iCode)<br> <nowiki>{</nowiki><br> case EKeyUpArrow:<br> case EKeyDownArrow:<br> <nowiki>{</nowiki><br> // Forward up and down key press events to the list box<br> return iListBox-<nowiki>></nowiki>OfferKeyEventL( aKeyEvent, aType );<br> <nowiki>}</nowiki><br> case EKeyOK: // display an information note when item is selected<br> <nowiki>{</nowiki><br> _LIT(KFormatMessage, "Selected item: %d");<br> TInt idx = iListBox-<nowiki>></nowiki>CurrentItemIndex();<br> TBuf<nowiki><</nowiki>32<nowiki>></nowiki> message;<br> message.Format(KFormatMessage, idx);<br> CAknInformationNote* Note = new (ELeave) CAknInformationNote;<br> Note-<nowiki>></nowiki>ExecuteLD(message);<br> return EKeyWasConsumed;<br> <nowiki>}</nowiki><br> default:<br> break;<br> <nowiki>}</nowiki><br> <br> return EKeyWasNotConsumed;<br> <nowiki>}</nowiki><br>Also make sure to add this line<br> AddToStackL( iAppView ); <br>in AppUi<nowiki>’</nowiki>s ConstructL() to add the view/container to the control stack and receive OfferKeyEventL() calls. | |
| − | ==== | + | |
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
[[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]] [[Category:S60 2nd Edition]] [[Category:S60 3rd Edition]] [[Category:S60 3rd Edition, Feature Pack 1]] | [[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]] [[Category:S60 2nd Edition]] [[Category:S60 3rd Edition]] [[Category:S60 3rd Edition, Feature Pack 1]] | ||
Revision as of 17:08, 4 November 2008
Article Metadata
Compatibility
S60 2nd Edition and FP1, FP2, FP3
S60 3rd Edition and FP1
Article
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 below:
http://wiki.forum.nokia.com/index.php/How_to_create_a_simple_listbox
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.

